Page 1 of 1

Howto get ListBoxItem from an ID?

Posted: Sun Dec 17, 2006 16:58
by realtiger
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

Posted: Sun Dec 17, 2006 18:29
by Rackle
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

Posted: Mon Dec 18, 2006 07:55
by realtiger
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.