ListView控制項使用

2021-04-02 19:55:43 字數 1187 閱讀 1862

在.h中

clistctrl m_listctrl;

在.cpp中

//新增listctrl標題

m_listctrl.insertcolumn(0,_t("標題"),lvcfmt_center); //第一欄設定center屬性不能成功

m_listctrl.setcolumnwidth(0,200);

m_listctrl.insertcolumn(1,_t("位置"),lvcfmt_center);

m_listctrl.setcolumnwidth(1,140);

//設定選擇整行屬性

dword dwstyle = m_listctrl.getextendedstyle();

dwstyle |= lvs_ex_fullrowselect;  //整行選擇

dwstyle |= lvs_ex_gridlines;      //網格線

m_listctrl.setextendedstyle(dwstyle);

//取得標題欄文字

int ncol = m_listctrl.getheaderctrl()->getitemcount();  //取得標題欄列數

hditem hdi;

hdi.mask = hdi_text;

tchar buffer[max_len] = ;  //必須先賦一臨時值後才能取出標題

hdi.psztext = buffer;

hdi.cchtextmax = max_len;

int nitem = m_listctrl.getitemcount();  //當前所有的記錄數

m_listctrl.insertitem(nitem,_t("")); //插入一行

m_listctrl.getheaderctrl()->getitem(i,&hdi);

cstring str = hdi.psztext;

m_combox.findstring(0,str);//在combox中查詢指定的字串

刪除listview中的記錄:

int ncount = m_listctrl.getitemcount();

//

注:應該從後往前刪除,因為如果從前刪除,則後面的記錄會上移,這樣會導致後面選中的記錄可能無法正確刪除

for (int i=ncount;i>=0;i--)

}

ListView控制項

listview的資料顯示 listview lv listview findviewbyid r.id.lv 通過游標方式 persondao dao newpersondao this cursor c dao.getpersons 結果集中必須有 id的字段,可以通過別名的方式指定 每乙個條目...

ListView 控制項使用方法記錄

1.選中一整行。a 需要設定擴充套件屬性 lvs ex fullrowselect。note 在建立時增加此屬性是無效的,必須使用 lvm setextendedlistviewstyle 訊息或者使用 clistctrl setextendedstyle 方法。使用setwindowlong應該也...

高階控制項ListView

baseadapter 是所有介面卡類的父類,可以對列表項進行最大限度的定製 1.1 自定義介面卡中的方法 getcount getview getitem getitemid 1.2 layoutinflater 布局解析器 layoutinflater有三種獲得方式,資料中有詳細介紹 用來把la...