ListBox多选的问题?

wujinbao 2001-06-20 03:08:00
ListBox可以多选,如何取得选中的数值?
有什么好方法?
...全文
266 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
TR@SOE 2001-06-20
  • 打赏
  • 举报
回复
还是用WINGSUN的方法稳妥。尽量用提供的属性来完成这个属性应该干的事。
cwpower 2001-06-20
  • 打赏
  • 举报
回复
遍历加个循环就行了呀
smartboyme 2001-06-20
  • 打赏
  • 举报
回复
To Wingsun(孙春阳): 
我的代码
if(ListBox1->ItemIndex)//判断是否已多选
和你的代码:
if(ListBox1->SelCount>0)
其实是一样的。我试过了。

这是帮助里的东东:
Use ItemIndex to select an item at runtime. Set the value of ItemIndex to the index of the item to be selected. The ItemIndex of the first item in the list box is 0. If no item is selected, the value is -1, which is the default value unless MultiSelect is true.

If the value of the MultiSelect property is true the user can select more than one item in the list box. In this case, the ItemIndex value is the index of the selected item that has focus. If MultiSelect is true
, ItemIndex defaults to 0.
Wingsun 2001-06-20
  • 打赏
  • 举报
回复
只有这样才可以访问时候所有已选中的项目
不过他们的方法有一点问题。改为:
if(ListBox1->SelCount>0)
{
for(int k=1;k<=ListBox1->Items->Count;k++)
{
if(ListBox1->Selected[k])
{
//do everything that you want to do.but,you don't delete this item,if you do it,you will find,the ListBox1->Items->Count was changed.
}
}
}
wujinbao 2001-06-20
  • 打赏
  • 举报
回复
二位说的都没有错,但是好象都要遍历整个ListBox1的Items!
不知道有没有什么别的更好的方法?
smartboyme 2001-06-20
  • 打赏
  • 举报
回复

//这样行吗?

if(ListBox1->ItemIndex)//判断是否已多选
{
for(int k=1;k<=ListBox1->Items->Count;k++)
{
if(ListBox1->Selected[k])
{
Application->MessageBox(ListBox1->Items->Strings[k].c_str(),"Infor",MB_OK);
//other operation
}
}
}
cwpower 2001-06-20
  • 打赏
  • 举报
回复
例:判断i是否被选中,如果是将数据读出到thestring
if(listbox->selected[i])
thestring=ListBox1->Items->Strings[listbox->ItemIndex]
smartboyme 2001-06-20
  • 打赏
  • 举报
回复
首先设置其MultiSelect为true.
多选时,被选中项的ItemIndex为true.

至少这样可以判断,我不知道还有没有别的方法。

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧