Fill a combobox
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 !
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 !
-
sfernandez
Site Admin
- Posts: 3008
- Joined:
Re: Fill a combobox
Hi Olivier,
If you are writing your application in C++, then you should proceed like follows:EDIT: Added GetPtr() as Olivier correctly pointed, thanks
If instead you are using the Unity integration and writing your code in C#, then:
Hope that helps
If you are writing your application in C++, then you should proceed like follows:
Code: Select all
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());
}
If instead you are using the Unity integration and writing your code in C#, then:
Code: Select all
void FillComboBox(ComboBox cb)
{
ItemCollection items = cb.GetItems();
items.Add(new TextBlock("800x600"));
items.Add(new TextBlock("1280x720"));
items.Add(new TextBlock("1920x1080"));
}
Re: Fill a combobox
I use NoesisGui with Ogre3D and so c++
Small correction for Add :
items->Add( Boxing::Box<NsString>("800x600").GetPtr() );
Thanks for help !
Small correction for Add :
items->Add( Boxing::Box<NsString>("800x600").GetPtr() );
Thanks for help !
Re: Fill a combobox
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
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
-
sfernandez
Site Admin
- Posts: 3008
- Joined:
Re: Fill a combobox
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.
The GetText/SetText functions are only useful when IsEditable is set to true in the ComboBox.
Code: Select all
const NsChar* GetSelectedItemText(ComboBox* cb)
{
Boxing::BoxedValue* boxed = NsStaticCast<Boxing::BoxedValue*>(cb->GetSelectedItem());
NS_ASSERT(boxed);
return Boxing::Unbox<NsString>(boxed).c_str();
}
Who is online
Users browsing this forum: Ahrefs [Bot] and 4 guests