noesis_user
Topic Author
Posts: 14
Joined: 08 May 2014, 00:04

Setting selected item in combo box

14 Apr 2015, 22:44

Hey,

I am trying to set the selected item into combo box. Something like below:
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);
    }
} 
Everything works fine till SetSelectedItem and it crashes then.

Any inputs?

Thanks.
 
User avatar
sfernandez
Site Admin
Posts: 1920
Joined: 22 Dec 2011, 19:20

Re: Setting selected item in combo box

17 Apr 2015, 16:44

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:
...
<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>
...
One question, are you changing the selected item inside any event handler of the ComboBox itself?

Thanks for your collaboration.
 
noesis_user
Topic Author
Posts: 14
Joined: 08 May 2014, 00:04

Re: Setting selected item in combo box

17 Apr 2015, 18:37

Nope.
Its kinda like reading a item saved in file and setting it again when app is up, like saving settings.
 
User avatar
jsantos
Site Admin
Posts: 2909
Joined: 20 Jan 2012, 17:18
Contact:

Re: Setting selected item in combo box

17 Apr 2015, 18:45

The crash is inside SetSelectedItem or after it?

Could you paste the stack trace here?
 
noesis_user
Topic Author
Posts: 14
Joined: 08 May 2014, 00:04

Re: Setting selected item in combo box

17 Apr 2015, 20:46

Crash is inside setSelectedItem.
 
User avatar
sfernandez
Site Admin
Posts: 1920
Joined: 22 Dec 2011, 19:20

Re: Setting selected item in combo box

17 Apr 2015, 20:56

Could you try using SetSelectedIndex instead?
Maybe this code route is working while we investigate what is happening.
 
noesis_user
Topic Author
Posts: 14
Joined: 08 May 2014, 00:04

Re: Setting selected item in combo box

17 Apr 2015, 20:58

setSelectedIndex doesn't work too.
 
User avatar
jsantos
Site Admin
Posts: 2909
Joined: 20 Jan 2012, 17:18
Contact:

Re: Setting selected item in combo box

20 Apr 2015, 17:29

Could you generate a minidump and attach it to a bug report?

Thanks!
 
tseiler
Posts: 8
Joined: 21 Oct 2013, 20:18

Re: Setting selected item in combo box

28 May 2015, 23:37

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;
}
 
User avatar
sfernandez
Site Admin
Posts: 1920
Joined: 22 Dec 2011, 19:20

Re: Setting selected item in combo box

03 Jun 2015, 13:41

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.
I have also have had this issue for a long time now, setting combo box items.
Maybe I'm missing something, could you please provide a simple sample where we can reproduce these problems you describe?

Thanks.

Who is online

Users browsing this forum: Google [Bot] and 2 guests