Olivier
Topic Author
Posts: 6
Joined: 22 Nov 2012, 20:41

Fill a combobox

16 Jan 2013, 23:32

Hello !

I continue to have fun with Noesisgui, and now I would like to fill a combobox with a list of resolution.
My problem ... i don't find the appropriate function ...

Thank for help !
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: Fill a combobox

17 Jan 2013, 01:51

Hi Olivier,

If you are writing your application in C++, then you should proceed like follows:
void FillComboBox(ComboBox* cb)
{
    ItemCollection* items = cb->GetItems();
    items->Add(Boxing::Box<NsString>("800x600").GetPtr());
    items->Add(Boxing::Box<NsString>("1280x720").GetPtr());
    items->Add(Boxing::Box<NsString>("1920x1080").GetPtr());
}
EDIT: Added GetPtr() as Olivier correctly pointed, thanks ;)

If instead you are using the Unity integration and writing your code in C#, then:
void FillComboBox(ComboBox cb)
{
    ItemCollection items = cb.GetItems();
    items.Add(new TextBlock("800x600"));
    items.Add(new TextBlock("1280x720"));
    items.Add(new TextBlock("1920x1080"));
}
Hope that helps ;)
 
Olivier
Topic Author
Posts: 6
Joined: 22 Nov 2012, 20:41

Re: Fill a combobox

19 Jan 2013, 18:28

I use NoesisGui with Ogre3D and so c++ :)

Small correction for Add :
items->Add( Boxing::Box<NsString>("800x600").GetPtr() );

Thanks for help !
 
Olivier
Topic Author
Posts: 6
Joined: 22 Nov 2012, 20:41

Re: Fill a combobox

20 Jan 2013, 20:25

Sorry for the equivalent question ...

But I don't find what function I need to use, to get the value of the selected item in my combobox.
I have try to use the GetText() function in my combobox, but it return empty.
I have try to use the function Get of Itemcollection with the index of my combobox, but I don't know what type use with a cast :s

I still have a little trouble to understand what type use with a cast when a function return a BaseElement ^^

I hope you can help me ;)
Thanks
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: Fill a combobox

21 Jan 2013, 12:58

To extract the text of the selected item in a ComboBox, it depends on the contents of the item. If you filled the ComboBox with a boxed string items, then you can extract the text by unboxing the selected item.
const NsChar* GetSelectedItemText(ComboBox* cb)
{
    Boxing::BoxedValue* boxed = NsStaticCast<Boxing::BoxedValue*>(cb->GetSelectedItem());
    NS_ASSERT(boxed);
    return Boxing::Unbox<NsString>(boxed).c_str();
}
The GetText/SetText functions are only useful when IsEditable is set to true in the ComboBox.

Who is online

Users browsing this forum: Ahrefs [Bot] and 51 guests