CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

请问如何得到ListBox中的一个或多外选项?

楼主ShaB(ShaB)2003-11-03 19:57:08 在 VC/MFC / 基础类 提问

我用GetCurSel(),SelCount()等属性,都不能得到想要的结果,我想取得选中的选项总数,还有各个选项的字符串内容,请问谁能帮帮忙写一下吗? 问题点数:0、回复次数:10Top

1 楼flyhigh(一不小心)回复于 2003-11-03 20:08:58 得分 0

看看msdn就好了,为什么要别人替你写?  
  下面是msdn中CListBox   class   member中关于多选操作的接口  
  Multiple-Selection   Operations  
   
  SetSel   Selects   or   deselects   a   list-box   item   in   a   multiple-selection   list   box.    
  GetCaretIndex   Determines   the   index   of   the   item   that   has   the   focus   rectangle   in   a   multiple-selection   list   box.    
  SetCaretIndex   Sets   the   focus   rectangle   to   the   item   at   the   specified   index   in   a   multiple-selection   list   box.    
  GetSelCount   Returns   the   number   of   strings   currently   selected   in   a   multiple-selection   list   box.    
  GetSelItems   Returns   the   indices   of   the   strings   currently   selected   in   a   list   box.    
  SelItemRange   Selects   or   deselects   a   range   of   strings   in   a   multiple-selection   list   box.    
  SetAnchorIndex   Sets   the   anchor   in   a   multiple-selection   list   box   to   begin   an   extended   selection.    
  GetAnchorIndex   Retrieves   the   zero-based   index   of   the   current   anchor   item   in   a   list   box.    
  Top

2 楼keiven()回复于 2003-11-03 20:57:17 得分 0

upTop

3 楼ManFred2ManFred(曼弗雷德)回复于 2003-11-03 21:13:04 得分 0

是啊,将来大家能不能别偷懒啊。我也是初学者,接触vc才不到三个月,但有些问题我觉得大家在提问前根本就没有查阅过资料么。在权威的专家也没有msdn讲得好啊!Top

4 楼ShaB(ShaB)回复于 2003-11-03 21:20:48 得分 0

我查了,但确实是查不懂,因为实在是刚接触VC一星期多,像上面的问题,我试了以后还是有以下疑问,希望大家能好人做到底,帮我解答一下。  
  void   CSBPlayerDlg::OnmnuMusicPlay()    
  {  
      CString   curPlayMusic;  
      int   i,selCount;  
      if(m_boxMusicList.GetSelCount()!=0){  
          selCount=m_boxMusicList.GetSelCount();       //取得总选择项目  
              //......如何在这里得到每一个选中的选项呢?  
              //我想用GetText(),但它需要指定一个索引,而我不知道如何取得被选择过的索引  
      }  
  }  
   
  是多选项的列表框,请指点!Top

5 楼ManFred2ManFred(曼弗雷德)回复于 2003-11-04 11:17:02 得分 0

int   nCount   =   m_DefList1.GetSelCount();  
  CArray<int,int>   aryListBoxSel;  
   
  aryListBoxSel.SetSize(nCount);  
  m_DefList1.GetSelItems(nCount,   aryListBoxSel.GetData());   //获得所有被选中的索引  
  for(i=0;   i<nCount;   i++)  
  {  
  CString   Tempbuffer;  
  m_DefList1.GetText(aryListBoxSel[i],   Tempbuffer);//获得每项的文字  
                    。。。//这里加入你的处理  
  }  
  Top

6 楼ManFred2ManFred(曼弗雷德)回复于 2003-11-04 11:20:25 得分 0

这次就帮你写了,但你真的是没有好好看msdn。这个例子就在CListBox的CListBox::GetSelItems的“Example”一节中。学会使用MSDN可是作VC程序员的第一课噢:)Top

7 楼caihong86(caihong86)回复于 2003-11-04 12:17:37 得分 0

先定义一个类型为CListBox的变量如m_list,  
  m_list.GetCount()得到整个list表中的总选项数目,  
  m_list.GetText(i,str)得到当前被选中的那项的内容,保存在CString型变量str中,其中i是当前被选中项在当前整个list表中的顺序号.Top

8 楼ManFred2ManFred(曼弗雷德)回复于 2003-11-04 13:39:40 得分 0

楼上的,不要误人子弟噢。Top

9 楼fbmsf(FBM)回复于 2003-11-04 14:03:23 得分 0

LB_GETSELCOUNT      
  An   application   sends   an   LB_GETSELCOUNT   message   to   retrieve   the   total   number   of   selected   items   in   a   multiple-selection   list   box.    
   
  LB_GETSELCOUNT      
  wParam   =   0;   //   not   used;   must   be   zero      
  lParam   =   0;   //   not   used;   must   be   zero    
  得到选种的总数。  
   
   
  LB_GETSELITEM  
  An   application   sends   an   LB_GETSELITEMS   message   to   fill   a   buffer   with   an   array   of   integers   that   specify   the   item   numbers   of   selected   items   in   a   multiple-selection   list   box.    
   
  LB_GETSELITEMS      
  wParam   =   (WPARAM)   cItems;                       //   maximum   number   of   items      
  lParam   =   (LPARAM)   (LPINT)   lpnItems;   //   address   of   buffer    
  得到选种的内容。Top

10 楼ablefirst(able)回复于 2003-11-04 14:07:04 得分 0

CListBox::GetSelCount    
  int   GetSelCount(   )   const;  
   
  Return   Value  
   
  The   count   of   selected   items   in   a   list   box.   If   the   list   box   is   a   single-selection   list   box,   the   return   value   is   LB_ERR.  
   
  Remarks  
   
  Top

相关问题

  • 【急】如何得到动态创建的ListBox中的选项值啊
  • 如何知道Listbox中所选项.
  • (未解决....在线等待....)在ListBoxcleck事件中,如何得到ListBox中的被选项的序号,或者直接返回该选项的文件名!(该选项的值为一文件
  • 如何删除listBox控件中的多个选项?
  • 请问如何判断listbox中是否有选项被选中
  • 用js如何在ListBox中插入一个新的选项
  • C# winform程序 如何取得listbox被选项的值
  • 如何得到select里选中的选项的selectedIndex的值?
  • listbox的选项值问题
  • 如何得到有两个选项的弹出对话框?(在线)

关键词

  • 选项
  • msdn
  • getselcount
  • arylistboxsel
  • selcount
  • 索引
  • 选中
  • list box
  • ncount
  • 得到

得分解答快速导航

  • 帖主:ShaB

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo