CListBox(列表框)控件


CListBox(列表框)控件

CListBox類常用成員

CListBox插入數據

CListBox刪除數據

CListBox運用示例

 

 

一、CListBox類常用成員

 

CListBox::ResetContent//清空組合框內容

void ResetContent( );

 

CListBox::AddString//添加lpszString 至組合框尾部

int AddString( LPCTSTR lpszString );

 

CListBox::DeleteString//刪除nIndex

int DeleteString( UINT nIndex );

 

CListBox::InsertString //nIndex行后,插入行

int InsertString( int nIndex, LPCTSTR lpszString );

 

CListBox::SelectString //可以選中包含指定字符串的行

int SelectString( int nStartAfter, LPCTSTR lpszString );

 

CListBox::FindString//可以在當前所有行中查找指定的字符傳的位置,nStartAfter指明從那一行開始進行查找。 

int FindString( int nStartAfter, LPCTSTR lpszString ) const;

 

CListBox::GetCount //獲取行數

int GetCount( ) const;

 

CListBox::GetCurSel//獲取當前選中行的行號

int GetCurSel( ) const;

 

CListBox::SetCurSel(n)//設置第n行內容為顯示的內容

int SetCurSel( int nSelect );

 

int CListBox::SetItemHeight( int nIndex, UINT cyItemHeight );//設置一個項的高度,注意:列表框具有

//LBS_OWNERDRAWVARIABLE風格才可以單獨設置一個項的高度,否則是所有項的高度

//------------------------上述函數與CListBox::CComboBox::::幾乎相同

 

int CListBox::GetText( int nIndex,CString &rString ) const;//根據索引獲得項文本  類似CComboBox::GetLBText

 

 

 

二、代碼示例

void CDialog_ListBoxTest::OnBnClickedButton1()

{

         // TODO: 在此添加控件通知處理程序代碼

         CListBox* plstbox=(CListBox*)GetDlgItem(IDC_LIST1);

         plstbox->AddString(L"xxxxxxxx");

        

}

 

int CDialog_ListBoxTest::OnInitDialog(void)

{

         CDialog::OnInitDialog();

         CListBox* plstbox=(CListBox*)GetDlgItem(IDC_LIST1);

         plstbox->AddString(L"1111");

         plstbox->AddString(L"2222");

         plstbox->AddString(L"3333");

         return 0;

}

 

void CDialog_ListBoxTest::OnBnClickedButton2()

{

         // TODO: 在此添加控件通知處理程序代碼

         CListBox* plstbox=(CListBox*)GetDlgItem(IDC_LIST1);

         //plstbox->DeleteString(0); //刪除指定行

         plstbox->DeleteString(plstbox->GetCurSel());

}

 

void CDialog_ListBoxTest::OnLbnDblclkList1()

{

         // TODO: 在此添加控件通知處理程序代碼

         //

         CListBox* plstbox=(CListBox*)GetDlgItem(IDC_LIST1);

         CEdit * pedt=(CEdit*)GetDlgItem(IDC_EDIT1);

         WCHAR ws[256];

         plstbox->GetText(plstbox->GetCurSel(),ws); //獲取選中文本存到ws

         //把文本送到編輯框里

         pedt->SetWindowText(ws);

   

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM