列表框的成员函数与使用用例

列表框的成员函数与使用用例:

通过ID操作对象

CListBox(列表框)控件

CListBox类常用成员

CListBox插入数据

CListBox删除数据

CListBox运用示例

 

 

一、CListBox类常用成员

 

CListBox::ResetContent//清空组合框内容

voidResetContent( );

 

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

intAddString( LPCTSTR lpszString );

 

CListBox::DeleteString//删除nIndex

intDeleteString( UINT nIndex );

 

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

intInsertString( int nIndex, LPCTSTR lpszString );

 

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

intSelectString( int nStartAfter, LPCTSTR lpszString );

 

CListBox::FindString//可以在当前所有行中查找指定的字符传的位置,nStartAfter指明从那一行开始进行查找。 

intFindString( int nStartAfter, LPCTSTR lpszString ) const;

 

CListBox::GetCount//获取行数

intGetCount( ) const;

 

CListBox::GetCurSel//获取当前选中行的行号

intGetCurSel( ) const;

 

CListBox::SetCurSel(n)//设置第n行内容为显示的内容

intSetCurSel( int nSelect );

 

intCListBox::SetItemHeight( int nIndex, UINTcyItemHeight );//设置一个项的高度,注意:列表框具有

//LBS_OWNERDRAWVARIABLE风格才可以单独设置一个项的高度,否则是所有项的高度

//------------------------上述函数与CListBox::CComboBox::::几乎相同

 

intCListBox::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");

         return0;

}

 

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);

         WCHARws[256];

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

         //把文本送到编辑框里

         pedt->SetWindowText(ws);

   

}



  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值