data from list box
data from list box
I need to get data from a list box, there are 3 choices in it, and i would like to get preferably an integer representing each choice, such as 1, 2, or 3. I think im supposed to use getIcon() but I cant for the life of me figure out how. Any ideas?
There's this function with a pretty descriptive name called It'll return the id of the - boing! - currently selected choice based on the ID you got returned calling when filling it.
Please, always have a look at the documentation first.
Cheers,
p.
Code: Select all
getSelected()
Code: Select all
addItem()
Please, always have a look at the documentation first.
Cheers,
p.
beer->setMotivationCallback(this);
I always start with the documentation before i end up posting, its just alot to go through and I dont always find it, thanks. That returns an s32, I made a function that wouldnt take that, so i just made it an int without converting and it didnt shoot out an error, im still having some issues so Im not sure if it works, can i do that?
heres what I mean, heres the event reciever part with this
case EGET_LISTBOX_CHANGED:
if(id==103)
{
GUIChange = true;
selectedTime = box->getSelected();
}
break;
and heres the function
int listBox(int selectedTime)
{
if(selectedTime == 0)
{
return 10;
}
if(selectedTime == 1)
{
return 6;
}
if(selectedTime == 2)
{
return 15;
}
}
heres what I mean, heres the event reciever part with this
case EGET_LISTBOX_CHANGED:
if(id==103)
{
GUIChange = true;
selectedTime = box->getSelected();
}
break;
and heres the function
int listBox(int selectedTime)
{
if(selectedTime == 0)
{
return 10;
}
if(selectedTime == 1)
{
return 6;
}
if(selectedTime == 2)
{
return 15;
}
}
I don't get it... you can certainly call "box->getSelected();" - but I guess you found that out yourself by now, so that's probably not what you are asking.
Do you want to get the selected text of the listbox?
Or the index of the item (so you can get the text later for example)?
Or a number which has nothing to do with either of them?
Or did you already try something and run into troubles? If so - what's the exact problem?
Do you want to get the selected text of the listbox?
Or the index of the item (so you can get the text later for example)?
Or a number which has nothing to do with either of them?
Or did you already try something and run into troubles? If so - what's the exact problem?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
I want to get a number representing each item, which i suppose is the index. The index is s32 data type. However, i could only use it in the function as an int. When i change the list box nothing is happening, so im assuming im doing something wrong. I'm pretty sure I have the redraw conditions for the gui right since i did it the same way that i did the resizing redraw, so im pretty sure the listbox stuff just isnt changing when i change the GUI. Is it something to do with using the index as an int?
Why shouldn't it be set on the first setting when you change the data? Or what would you expect to happen?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
I can't reproduce this. When I change the active setting of a combobox it does show the new selected setting.
Maybe you reset it somehow?
Maybe you reset it somehow?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hehe - trust your compiler. But if you post the code of what you are doing someone might be able to help you.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
so what are you using, a listbox or a combobox ???circusdan wrote:im using getIcon()
a combobox has no function callet getIcon() !!!
also I doubt this is what you want, or do you want to get the icon of an element ???
try getSelected()...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Im using a combo box, I am using getSelected,not getIcon. the code for that is all spread out but ill post it as best as i can.
Heres my reciever:
Here is a function i use with the combo box information
Here is where i use the combo box information to set the list box
If you need to see my reciever class and function that creates it I can post that too
Heres my reciever:
Code: Select all
case EGET_COMBO_BOX_CHANGED:
if(id==103)
{
selectedTime = box->getSelected();
GUIChange = true;
}
break;
Code: Select all
int numberOfLobbies(int time, server *object)
{
int speedVar;
int x;
int y;
int z;
if(time == 0)
{
x = 0;
for(i=0; i < lobbies; i++)
{
speedVar = object[i].getSpeed();
if(speedVar == 0)
{
x++;
}
}
return x;
}
if(time == 1)
{
y = 0;
for(i=0; i < lobbies; i++)
{
speedVar = object[i].getSpeed();
if(speedVar == 1)
{
y++;
}
}
return y;
}
if(time == 2)
{
z = 0;
for(i=0; i < lobbies; i++)
{
speedVar = object[i].getSpeed();
if(speedVar == 2)
{
z++;
}
}
return z;
}
}
Code: Select all
server servers[50];
server object[] = {createServers(servers, _countof(servers))};
IGUIListBox *list = mygui->addListBox(rect<s32>(componantX, componantY,
componantWidth+componantX, componantY+componantHeight), 0, 104);
i = 1;
while(i <= numberOfLobbies(selectedTime, object))
{
wCharString = core::stringw(listText.c_str());
wCharString += i;
list->addItem(wCharString.c_str());
i++;
}
I've edited your post a little - please take a look at those labels above the box where you write your posts. With the code label you can mark code which makes it a lot more readable (you can also see that now when you click "edit" for the post I've changed.
Ok, your code clears up a little confusion - you are not working with one element going wrong, but it seems you have 2 gui-elements - a listbox _and_ a combobox. But now we still don't know what exactly is your problem. What is displayed wrong? The combobox or your listbox? And what exactly is wrong there? And what did you expect to happen if everything would function correctly? You have to realize that we don't see what's happening on your screen - so the only way we can understand what you see and what is going wrong is if you describe it very(!) precisely. Don't hesitate to add screenshots if words are not sufficient - you can use a free image-service like imgur.com to upload screenshots.
I see no obvious bug in your code. Although I can give you a few hints which are unrelated, but might help you in the long run when you do coding:
First you should avoid fixed-sized arrays in c++ (like servers[50]) unless you have a very, very good reason to use them. In 99.9% of all cases you will have an easier life by using a dynamic array like irr::core::array or std::vector (both work in a similar way). Those will catch a lot of accidental bugs you might run into otherwise.
If you ever work with a fixed-size array, then try to avoid using magic-numbers (like 50), but use constants or defines instead. Sooner or later you will change the size and forget it in some other place otherwise.
Then you should make variable-names tell what they are used for - not what type they are. Anyone reading your code can see the type, but a name like wCharString doesn't tell the reader anything, while lobbyName (or wLobbyName if you absolutely want the wchar_t info) would be telling. Same goes for "object" - I guess every programmer once called an object with that name, but as every object is an object you will pretty soon stop calling it like that - so just start now.
Ok, your code clears up a little confusion - you are not working with one element going wrong, but it seems you have 2 gui-elements - a listbox _and_ a combobox. But now we still don't know what exactly is your problem. What is displayed wrong? The combobox or your listbox? And what exactly is wrong there? And what did you expect to happen if everything would function correctly? You have to realize that we don't see what's happening on your screen - so the only way we can understand what you see and what is going wrong is if you describe it very(!) precisely. Don't hesitate to add screenshots if words are not sufficient - you can use a free image-service like imgur.com to upload screenshots.
I see no obvious bug in your code. Although I can give you a few hints which are unrelated, but might help you in the long run when you do coding:
First you should avoid fixed-sized arrays in c++ (like servers[50]) unless you have a very, very good reason to use them. In 99.9% of all cases you will have an easier life by using a dynamic array like irr::core::array or std::vector (both work in a similar way). Those will catch a lot of accidental bugs you might run into otherwise.
If you ever work with a fixed-size array, then try to avoid using magic-numbers (like 50), but use constants or defines instead. Sooner or later you will change the size and forget it in some other place otherwise.
Then you should make variable-names tell what they are used for - not what type they are. Anyone reading your code can see the type, but a name like wCharString doesn't tell the reader anything, while lobbyName (or wLobbyName if you absolutely want the wchar_t info) would be telling. Same goes for "object" - I guess every programmer once called an object with that name, but as every object is an object you will pretty soon stop calling it like that - so just start now.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm