请问如何得到ListBox中的一个或多外选项?
我用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




