Getting index of selected item in MultilistBox

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
Shift
Just popping in
Just popping in
Posts: 8
Joined: Wed Jan 12, 2005 12:06

Getting index of selected item in MultilistBox

Postby Shift » Tue Aug 31, 2004 13:16

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?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Getting index of selected item in MultilistBox

Postby CrazyEddie » Tue Aug 31, 2004 13:28

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.

User avatar
Shift
Just popping in
Just popping in
Posts: 8
Joined: Wed Jan 12, 2005 12:06

Getting index of selected item in MultilistBox

Postby Shift » Tue Aug 31, 2004 16:37

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.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Getting index of selected item in MultilistBox

Postby CrazyEddie » Tue Aug 31, 2004 17:58

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.

User avatar
Shift
Just popping in
Just popping in
Posts: 8
Joined: Wed Jan 12, 2005 12:06

Getting index of selected item in MultilistBox

Postby Shift » Tue Aug 31, 2004 21:16

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


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 3 guests