ComboBox selected item issue RRS feed

  • Question

  • Hi,

    If you try to do something like : handle the selection_changed event from the combo box, and fire some confirmation on selection changed, and only if the confirmation goes true, I want to change the selected item, otherwise I must keep the old selection. Because the event is fired after the selection has changed I keep the old item so I can changed it back. All good until now. But not only that selected index and selected item aren't synchronized ( so you can have a selected item different from Items[SelectedIndex] ) if you manually set this two selected properties ( selected item and selected index ) and take care of the synchronization yourself, you must take care of the IsSelected property of the ComboBoxItem, because this is not handled by itself.

    This is really weird because, if you set an ItemsSource like a list of some class, I don't know how to get the ComboBoxItem after that. So I have to use a list of ComboBoxItem as the ItemsSource which clearly limits my options here.

    This isn't really a bug, but it's something that I think has to be corected, at least the issue with CombBoxItem remaining IsSelected = true, when SelectedIndex and SelectedItem change and ItemSource is something different from ComboBoxItem.


    Thursday, March 26, 2009 7:39 AM


  •  Hi,

    I used list class data for my EmployeeData class. That class file have a two fields, Name and Id.
    So, When am get from combobox, assigned to this list class and get that selected id.

    Dim objEmp as EmployeeData
    objEmp = cmboEmployee.SelectedItem

    And, if we need to select item for particular id, then im getting from below code.

    For i = 0 To cmboEmployee.Items.Count - 1
                    Dim objEmp As EmployeeData
                    objEmp = cmboEmployee.Items(i)
                    If objEmp.EmployeeId=10 Then
                        cmboEmployee.SelectedItem = cmboEmployee.Items(i)
                        Exit For
                    End If


    Thursday, March 26, 2009 8:36 AM