[Solved]Listbox: get text from certain element

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Lo_Ord
Posts: 12
Joined: Thu Apr 27, 2006 2:24 pm

[Solved]Listbox: get text from certain element

Post 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
Last edited by Lo_Ord on Mon May 29, 2006 1:05 pm, edited 1 time in total.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post 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());
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Elise
Posts: 48
Joined: Tue Jul 19, 2005 6:30 am
Contact:

Post 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
Lo_Ord
Posts: 12
Joined: Thu Apr 27, 2006 2:24 pm

Post by Lo_Ord »

Sorry, I totally forgot about this thread...

Elise, your solution works perfectly, thanks!
Post Reply