Page 1 of 1

[Solved]Listbox: get text from certain element

Posted: Wed May 10, 2006 2:54 pm
by Lo_Ord
Hi!

I got a little problem concerning listboxes:

We are working on a game project and I'm responsible for the Menus and Gui.
I'm currently working on the graphics-menu: I made a listbox and added 4 standard-resolutions to it ( with addItem()). It perfectly works.

Now I want to give the user the possibility to select one of the resolutions, click on the apply button and voila: resolution changes!

Now here is my problem: I wanted to get the text from the selected item:

Code: Select all

IGUIListBox *box;
s32 selected;
const wchar_t str;

//added items to the box

//now i'm trying to get the string of the selected resolution:
if ((selected = box->getSelected()) != -1=
{
     str = box->getElementFromId(selected)->getText();
}
//change resolution
It seems logically for me to do it this way, no compile errors appear. However, if I start the program, an error appears.

It seems, that if i select something other than the Element(0) the game hangs up. And the text of the Element(0) is an empty string, but is correctly displayed in the listbox.

Strangly all other elements seem to have correctly assigned id's, I just cannot access them without an error...

Can anybody help me?

Regards

Lo_Ord

Posted: Wed May 10, 2006 3:08 pm
by Acki
I don't really know, but could it be that "selected" is the element itself and not the ID ???
Did you try this:

Code: Select all

strcpy(str, selected->getText());

Posted: Wed May 10, 2006 3:54 pm
by Elise
Didn't test but something like this should work:

Code: Select all

IGUIListBox *box; 
s32 selected; 
const wchar_t *str; 

//added items to the box 

//now i'm trying to get the string of the selected resolution: 
if ((selected = box->getSelected()) != -1)
{ 
     str = box->getListItem(selected);
} 
//change resolution

Posted: Mon May 29, 2006 1:05 pm
by Lo_Ord
Sorry, I totally forgot about this thread...

Elise, your solution works perfectly, thanks!