練習使用CListBox

2021-04-02 06:11:46 字數 1289 閱讀 8678

該例是個小練習,有兩個listbox控制項,可以通過其中的四個button按鈕,實現從乙個listbox向另乙個listbox中傳遞資料,操作過程如下:

1、建立乙個dialog based mfc應用程式,命名為try。

2、為對話方塊新增兩個lsitbox控制項,分別命名為idc_list1和idc_list2

3、開啟classwizard,分別為idc_list1和idc_list2新增clistbox型別的變數m_list1和m_list2與之相關聯

4、再為對話方塊新增四個button控制項,分別命名為idc_to_right、idc_to_left、idc_right_all、idc_left_all

5、再次開啟classwizard,為剛才新增的button控制項新增訊息響應函式。響應bn_click訊息,訊息響應接受預設選專案,分別為:void ctrydlg::ontoright()、void ctrydlg::ontoleft()、void ctrydlg::onrightall()、void ctrydlg::onleftall()

6、選擇idc_list1控制項,選擇"屬性"->styles->selections->extended,對idc_list2採取同樣的操作

7、對ontoleft新增如下**

void ctrydlg::ontoleft()

int buf[10];

cstring str;

int number = m_list2.getselitems(max_num,buf);

for(int i=0;ifor(i=0;i8、對ontoright新增如下**

void ctrydlg::ontoright()

int buf[10];

cstring str;

int number = m_list1.getselitems(max_num,buf);

for(int i=0;ifor(i=0;i9、對onrightallt新增如下**

void ctrydlg::onrightall()

cstring str;

for(int i=0;ifor(i=0;i10、對onleftallt新增如下**

void ctrydlg::onleftall()

cstring str;

for(int i=0;ifor(i=0;i11、最後,在oninitupdate函式中,新增

cstring str;

for(int i=0;i<10;i++)

為list1新增了10條記錄

12、現在執行下程式,看看效果吧:)

C listbox使用方法

1.屬性列表 selectionmode 元件中條目的選擇型別,即多選 multiple 單選 single rows 列表框中顯示總共多少行 selected 檢測條目是否被選中 selecteditem 返回的型別是listitem,獲得列表框中被選擇的條目 count 列表框中條目的總數 se...

C ListBox資料互換

c 中兩個listbox資料互換的邏輯,下面為一段例項code,供參考。private void btn2right click object sender,system.eventargs e delete item from listbox1,when it add item to listbo...

CListBox 控制項用法總結

clistbox新增項,得到選中的單項或多項的值。1 首先新增乙個對話方塊,並建立這個對話方塊的類。2 在主選單藍欄中新增乙個選單 列表框 並新增這個選單的單擊事件 在oninitdialog 中隊列表框進行初始化。bool cuserdlg oninitdialog void cuserdlg o...