24课时VC之思考->列表框与组合框

 

                               列表框和组合框


 

             

一、添加

listBox.AddString("Gwen"); InsertString 和 Addstring函数都返回新加入的列表项的位置。若在整加列表项时候 发生错误,InsertString 和 Addstring函数将返回LB_ERR。如果列表框满了,将返回 LB_ERRSPACE.

 

二、删除

listBox.DeleteString(8); 这一行代码删除了列表框中第9个位置的列表框。记住,所有的列表框的位置索引从零 开始。从DeleteString成员函数中返回的值是列表框中所剩列表项的数字,如果发生 错误,则为LB_ERR。返回值可如下使用:

int nItems=listBox.GetCount();

while(nItems>3&&nItems!=LB_ERR)

nItems=listBox.DeleteString(nItems-1);

此代码删除前3个列表框之后的所有列表项。若要完全删除列表项,需要使用ResetCount函数: listBox.ResetCount(); ResetCount返回位Void(空)。

LBN_,是List BOX Notification的简称。 ClistBox::GetCursel成员函数决定列表框当前选择的列表项。

 

1.给组合框增加列表项 :

comboBox.AddString("Riley"); 或 comboBox.InsertString(0,"Mitch");

如果有错误发生,将被返回CB_ERR而不是LB_ERR 同理,CB_ERRSPACE nItems=comboBox.GetCount();

 

2.从组合框中获取收入:

m_combo.GetLBText(1,szChoice);

 

3.在组合框中查找列表项:

FindString和FindStringExact成员函数查找一个特定的列表项。

int index=m_combo.FinString(-1,szSearch); 搜索索引指定第一个被找到的列表项索引之前的列表项,因此在开始搜寻索引时必须对索引 减一作为搜索索引。

FindStringExact函数在组合框中搜索与搜索字符串精确匹配的列表项,它与FindString函数 使用相同的参数: int index=m_combo.FindStringExact(-1,szSearch);

CComboListDlg::OnCloseupCombo函数收集组合框编辑控件部分的内容和组合框列表框中所选择 的列表项。

 


1.

void CListBoxDlg::OnDblclkList() {  // TODO: Add your control notification handler code here  

int nSelection=m_listBox.GetCurSel();

 if(nSelection!=LB_ERR)  {     

CString szSelection;  

m_listBox.GetText(nSelection,szSelection);  

AfxMessageBox(szSelection);

 }

}


 

2.

void CListBoxDlg::OnCloseupCombo() {  // TODO: Add your control notification handler code here  

CString szChoice;  

CString szResult;  

int nChoice;

 m_comboList.GetWindowText(szChoice);

 nChoice=m_comboList.GetCurSel();  

if(nChoice!=CB_ERR)  {    

m_comboList.GetLBText(nChoice,szChoice);

 szResult="Closing after selecting"+szChoice;

 }      

else if(szChoice.IsEmpty()==TRUE)  {     

szResult="No choice selected";  }

 else if(

m_comboList.FindStringExact(-1,szChoice)!=CB_ERR)

{    

szResult="Closing after selecting"+szChoice;

 }

 else  {    

m_comboList.AddString(szChoice);

 szResult="Adding "+szChoice+ " to list";

 }  

CWnd *pWnd=GetDlgItem(ID_RESULT);  

ASSERT(pWnd);  

if(pWnd){    

pWnd->SetWindowText(szResult);

 }

}


3.

void CListBoxDlg::OnEditupdateCombo() {  // TODO: Add your control notification handler code here  

CString szChoice;  

CString szResult;  

m_comboList.GetWindowText(szChoice);    

szResult="Choice changed to "+szChoice;  

CWnd *pWnd=GetDlgItem(ID_RESULT);  

ASSERT(pWnd);

 if(pWnd)   

pWnd->SetWindowText(szResult);

}

 

 
 
  
 
  
  
  
  
  
  
  
  
  
  
  
  
 
 
 



  
  
  
  
  
  
  
  
  
  
  
 
 
 


 

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/fengbo/archive/2012/08/08/2629003.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值