locked
Set value of a custom type combobox RRS feed

  • Question

  • Hi,

    I wonder why this code doesn't work (also the remarked row doesn't work). The m.TwoStrings type consists of two strings.

    ObservableCollection<m.TwoStrings> lstsource = (ObservableCollection<m.TwoStrings>)cmbType.ItemsSource;
                    foreach (m.TwoStrings ts in lstsource)
                    {
                        int i = lstsource.IndexOf(ts);
                        //if (ts.String1 == gp.gpType && i != -1) cmbType.SelectedItem = ts;
                        if (ts.String1 == gp.gpType && i != -1) cmbType.SelectedIndex = i;
                    }

    I get: "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))" when trying to set the selecteditem/selectedindex.

    Best regards
    /Magnus

    Wednesday, October 16, 2013 9:32 AM

All replies

  • It's not clear what your objective is with this code.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, October 17, 2013 12:55 PM
    Moderator