Howto get ListBoxItem from an ID?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

User avatar
realtiger
Just popping in
Just popping in
Posts: 12
Joined: Thu Dec 14, 2006 05:10

Howto get ListBoxItem from an ID?

Postby realtiger » Sun Dec 17, 2006 16:58

Hi all

This is the way I add an item to a list box.

Code: Select all

   CEGUI::ListboxTextItem *item = new CEGUI::ListboxTextItem(userName, id, p);
   item->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
   m_playerListBox->addItem(item);
   m_playerListBox->ensureItemIsVisible(item);


Now I want to get this item from the ID.
Can I do so? If not why CEGUI uses ID?

Thank you

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Sun Dec 17, 2006 18:29

http://www.cegui.org.uk/wiki/index.php/WidgetGalore

If you want to get the ID of the selected item you can use:
uint valueListbox = listbox->getFirstSelectedItem()->getID();

If you want to retrieve the ListboxItem* from an ID then the following should work:

Code: Select all

         CEGUI::uint findID = 1234;
         CEGUI::ListboxItem* listboxItem;
         for(size_t listboxItem = 0; listboxItem < listbox->getItemCount(); listboxItem++)
         {
            listboxItem = listbox->getListboxItemFromIndex(listboxItem);
            if(listboxItem && listboxItem->getID() == findID)
            {
               // Found it
            }
         }
         // Did not find it

User avatar
realtiger
Just popping in
Just popping in
Posts: 12
Joined: Thu Dec 14, 2006 05:10

Postby realtiger » Mon Dec 18, 2006 07:55

Rackle wrote:http://www.cegui.org.uk/wiki/index.php/WidgetGalore

If you want to get the ID of the selected item you can use:
uint valueListbox = listbox->getFirstSelectedItem()->getID();

If you want to retrieve the ListboxItem* from an ID then the following should work:

Code: Select all

         CEGUI::uint findID = 1234;
         CEGUI::ListboxItem* listboxItem;
         for(size_t listboxItem = 0; listboxItem < listbox->getItemCount(); listboxItem++)
         {
            listboxItem = listbox->getListboxItemFromIndex(listboxItem);
            if(listboxItem && listboxItem->getID() == findID)
            {
               // Found it
            }
         }
         // Did not find it


Thank you, I tried it.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 14 guests