-
- noesis_user
- Posts: 14
- Joined:
Setting selected item in combo box
Hey,
I am trying to set the selected item into combo box. Something like below:
Everything works fine till SetSelectedItem and it crashes then.
Any inputs?
Thanks.
I am trying to set the selected item into combo box. Something like below:
Code: Select all
auto combo_box = NsDynamicCast<Noesis::Gui::ComboBox*>(getNamedElement(
user_control_.GetPtr(), MODEL_COMBO_BOX_NAME));
auto items = combo_box->GetItems();
for ( int i = 0 ; i < items->Count() ; ++i )
{
auto item = NsDynamicCast<Noesis::Gui::ComboBoxItem*>(items->Get(i));
if ( item == nullptr ) continue ;
if ( item->GetName() == combo_box_item_name.c_str() )
{
combo_box->SetSelectedItem(item);
}
}
Any inputs?
Thanks.
-
-
sfernandez
Site Admin
- Posts: 3250
- Joined:
Re: Setting selected item in combo box
Hi,
Could you please create a ticket in our bugtracker and attach the crash dump and log files?
Because I tried with a sample xaml like this, and it works as expected:
One question, are you changing the selected item inside any event handler of the ComboBox itself?
Thanks for your collaboration.
Could you please create a ticket in our bugtracker and attach the crash dump and log files?
Because I tried with a sample xaml like this, and it works as expected:
Code: Select all
...
<ComboBox x:Name="TheComboBox">
<ComboBoxItem Name="item1" Content="Value 1"/>
<ComboBoxItem Name="item2" Content="Value 2"/>
<ComboBoxItem Name="item3" Content="Value 3"/>
<ComboBoxItem Name="item4" Content="Value 4"/>
</ComboBox>
...
Thanks for your collaboration.
-
- noesis_user
- Posts: 14
- Joined:
Re: Setting selected item in combo box
Nope.
Its kinda like reading a item saved in file and setting it again when app is up, like saving settings.
Its kinda like reading a item saved in file and setting it again when app is up, like saving settings.
Re: Setting selected item in combo box
The crash is inside SetSelectedItem or after it?
Could you paste the stack trace here?
Could you paste the stack trace here?
-
- noesis_user
- Posts: 14
- Joined:
Re: Setting selected item in combo box
Crash is inside setSelectedItem.
-
-
sfernandez
Site Admin
- Posts: 3250
- Joined:
Re: Setting selected item in combo box
Could you try using SetSelectedIndex instead?
Maybe this code route is working while we investigate what is happening.
Maybe this code route is working while we investigate what is happening.
-
- noesis_user
- Posts: 14
- Joined:
Re: Setting selected item in combo box
setSelectedIndex doesn't work too.
Re: Setting selected item in combo box
I have also have had this issue for a long time now, setting combo box items.
The workaround I have discovered is to:
1) Use "SetSelectedIndex". This will select the correct item, and display the proper item in box.
2) Do not use "SetSelectedItem". This will select the correct item and NOT display the proper item in the box.
3) Wrap the call in a try{}catch(...){}.
Whatever it throws, I just ignore it and continue on as if nothing happened.
Like this:
try
{
//combo->SetSelectedItem(item);
combo->SetSelectedIndex(i);
}
catch(...)
{
std::cout << "dunno." << std::endl;
}
The workaround I have discovered is to:
1) Use "SetSelectedIndex". This will select the correct item, and display the proper item in box.
2) Do not use "SetSelectedItem". This will select the correct item and NOT display the proper item in the box.
3) Wrap the call in a try{}catch(...){}.
Whatever it throws, I just ignore it and continue on as if nothing happened.
Like this:
try
{
//combo->SetSelectedItem(item);
combo->SetSelectedIndex(i);
}
catch(...)
{
std::cout << "dunno." << std::endl;
}
-
-
sfernandez
Site Admin
- Posts: 3250
- Joined:
Re: Setting selected item in combo box
Hi,
I've tried both scenarios in NoesisGUI 1.2.3: filling the ComboBox.Items with ComboBoxItems, or using the ItemsSource property providing a list of data items. In both cases modifying SelectedItem worked as expected, without crash, and selected item is visually updated.
Thanks.
I've tried both scenarios in NoesisGUI 1.2.3: filling the ComboBox.Items with ComboBoxItems, or using the ItemsSource property providing a list of data items. In both cases modifying SelectedItem worked as expected, without crash, and selected item is visually updated.
Maybe I'm missing something, could you please provide a simple sample where we can reproduce these problems you describe?I have also have had this issue for a long time now, setting combo box items.
Thanks.
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest