views:

633

answers:

1

I am successfully databinding and using WPF Comboboxes and have had some success with cascading some of the Comboboxes by triggering the update on the child combo when the parent combos SelectionChanged event is triggered. My combos are cboCountry, cboCity and cboTown.

However, this isn't reliable as it seems to blank the selected value in the child combo when the parent triggers an update in the child combos dropdown contents.

Has anyone experienced this behaviour (and has resolved it) or does anyone have any code that is successfully working without this issue?

Private Sub cboArea_SelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles cboArea.SelectionChanged
    Dim drv As DataRowView = CType(CType(e.Source, ComboBox).SelectedItem, DataRowView)
    If Not IsNothing(drv) Then
        Dim Area As String = drv(0).ToString
        Dim dv As New DataView(gLookupTown, "ItemGrouping = '" & Area & "'", "ItemValue", DataViewRowState.CurrentRows)
        cboTown.ItemsSource = dv
    End If
End Sub
+1  A: 

This is because you're changing the ItemsSource of the ComboBox. Without a code sample I can't tell you how to fix it. The best option is to filter an ObservableCollection based on the parent ComboBox's value so that you don't need to change the child ItemsSource. You can also try resetting the SelectedValue when the ItemsSource changes.

Bryan Anderson
Hi Bryan, thanks for your reply. Great idea about setting the ItemsSource to the entire list then filtering it, I've now added some code snippets. However, I'm not sure how to filter a Combo thats ItemsSource has been attached to a DataView without filtering the DataView and attaching it again thus causing the problem again. Any ideas how to filter a Combo based on a DataView?
Mitch
Don't worry I've worked it out. Many thanks Bryan for pointing me in the right direction.
Mitch
And how is this filter achieved?
Shimmy
Bea will get you started: http://bea.stollnitz.com/blog/?p=31 This is from before WPF was released so you can set up the CollectionViewSource in XAML now but this method still works.
Bryan Anderson
still sux, since why does he care when i change the ItemsSource!?
Shimmy