Multiple/Single Selection ListBox Control
The SRListBox class is implemented by taking a multiple selection listbox that can be made to behave like a single select listbox. In the single select mode I simply unselect any other selections made. The SRListBox provides the user with a function ( SetSingleSelect(const bool& single) ) to toggle between single and multiple selection.
In addition to this simple implementation I added and array of class SRCBAndLBItemArray. This class simply holds pointers to all items currently selected. This saves me having to go through the painful routine of repeating the code below each time I need my selections.
int numberSelected = GetSelCount();
if (numberSelected>0)
{
int *selIndex = new int[numberSelected];
GetSelItems( numberSelected, selIndex );
for (int i=0; i < numberSelected; i++)
{
blah....
}
}
The SRCBAndLBItemArray gets populated each time the SRListBox::UpdateData() function gets called (perhaps I should have given this function another name). I call this function from the DoDataExchange(CDataExchange* pDX) function of parent window and from the OnSelectionChange message handler. (this is key, without it the SRCBAndLBItemArray does not get populated). Perhaps someone can suggest a better mechanism.
The CListBoxExDlg::OnSelchangeList1() function in the sample code displays the use of the SRListBox data retrieval.

Comments
Simpler Solution!?
Posted by Legacy on 05/04/1999 12:00amOriginally posted by: Bryan C. Smith
ReplyLimit Multiple Listbox to 2 selections?
Posted by Legacy on 01/19/1999 12:00amOriginally posted by: Ryan Hayle
I am trying to figure out if this is possible. I see I could use your implementation, and just unselect everything after the second selection, but there must be a better way.
Thanks,
ReplyRyan Hayle
<ryan@savvynet.com>