Getting a value from a listbox

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
ortsa
Posts: 11
Joined: Sun Jul 27, 2008 4:14 pm

Getting a value from a listbox

Post by ortsa »

Hey everyone,
Im trying to get the value(the wchar_t text) from the currently selected item on a list box, whats the best way for me to do this what iv tried isnt working, its so i can set the text of a StaticText object.

Thanks
Jallenbah
Posts: 12
Joined: Thu Aug 14, 2008 12:10 pm
Location: Vector3df(20.6, 4, 19.2);

Post by Jallenbah »

http://irrlicht.sourceforge.net/docu/cl ... ox.html#a9

How about actually telling us what you're trying?
ortsa
Posts: 11
Joined: Sun Jul 27, 2008 4:14 pm

Post by ortsa »

What im trying is this

Code: Select all

statictext->setText(listbox->getListItem(listbox->getSelected()))
This is called when i get the gui event for changing or re selecting an item in the list box, the problem is that the statictext just goes blank when i select an item.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Works For Me.

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif


IGUIListBox* listbox = 0;
IGUIStaticText * statictext = 0;

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(const SEvent& event)
	{
		if (event.EventType == EET_GUI_EVENT
            &&
            event.GUIEvent.EventType == EGET_LISTBOX_CHANGED)
		{
            statictext->setText(listbox->getListItem(listbox->getSelected()));
		}

		return false;
	}
};


int main()
{
	IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480));

	MyEventReceiver receiver;
	device->setEventReceiver(&receiver);

	video::IVideoDriver* driver = device->getVideoDriver();
	IGUIEnvironment* env = device->getGUIEnvironment();

	statictext = env->addStaticText(L"", rect<s32>(10,10,250,30), true);

	listbox = env->addListBox(rect<s32>(10, 30, 250, 210));
	listbox->addItem(L"Some text");
    listbox->addItem(L"Some more text");
    listbox->addItem(L"Yet more text");
    
	while(device->run() && driver)
	if (device->isWindowActive())
	{
		driver->beginScene(true, true, SColor(0,200,200,200));
		env->drawAll();
		driver->endScene();
	}

	device->drop();

	return 0;
}
Verdict: Root Cause 17.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
ortsa
Posts: 11
Joined: Sun Jul 27, 2008 4:14 pm

Post by ortsa »

Well i looked through your code and noticed that i had left the text border to its default false setting that too true fixed the problem thanks
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I also Works For Me with a static text with no border, but you march to the beat of your own drum.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply