Page 1 of 1

Getting index of selected item in MultilistBox

Posted: Tue Aug 31, 2004 13:16
by Shift
I have searched the forums for this, I have read the code from the available demo, I have tried exotic code combinations, I have tried

Code: Select all

int index = mclbox->getItemColumnIndex(mclbox->getFirstSelectedItem());
This always returns 0 regardless of what is selected. Here is my simple question : How do I get the index from the currently selected item in a multilistbox?

Getting index of selected item in MultilistBox

Posted: Tue Aug 31, 2004 13:28
by CrazyEddie
Because the MultiColumnList is a grid widget you have columns and rows, I'm not sure which you're after, but this might give you what you need:

Code: Select all

MCLGridRef gridRef = mclbox->getItemGridReference(mclbox->getFirstSelectedItem());


You can then access the row and column of the item. I haven't tested this since I have no real access to anything until I rebuild my main development system later this week. But providing there's no bugs, the above should work :)

HTH

CE.

Getting index of selected item in MultilistBox

Posted: Tue Aug 31, 2004 16:37
by Shift
What I really am after is the index of the line item, not the data inside the grid coordinate.

Here is my situation, hoping to better describe my problem :

I have a mclistbox reflecting the contents of a data structure. The structure is accessed by a key index which points to the proper data in the structure. Without the index, I don't know which data to access.

Getting index of selected item in MultilistBox

Posted: Tue Aug 31, 2004 17:58
by CrazyEddie
The 'row' in the grid co-ordinate is the line index of the item/line within the list. So row 0 is the top line, row 1 is the second line, and so on.

The method posted earlier just returns a struct that contains the (row,column) pair that identifies the position of an item within the list. The row field within that struct is the line number that the item is on, and therefore the selected line index.

If this is still unacceptable (though I don't see why it should be), you might consider setting the ID or UserData for the items in the list, and use these to point to, or index the data within your structure.

Getting index of selected item in MultilistBox

Posted: Tue Aug 31, 2004 21:16
by Shift
I had overlooked that detail and thought this was a handle of some kind. My sincere apologies. My forum title says it all : Total Newbie :oops:

Works #1 now. Many thanks!!! :D