Crystal
Crystal

Reputation: 29448

Help with the Action/Event behind a ComboBox

I've been looking at this post to help populate my ComboBox: Binding WPF ComboBox to a Custom List.

My ComboBox is populated with an object, where a "name" property populates the list. This is what it looks like so far:

<ComboBox x:Name="SampleComboBox" ItemsSource="{Binding Path=SelectedSamples}" DisplayMemberPath="SampleName" SelectedValue="{Binding Path=SampleName}"
                          SelectedItem="{Binding Path=SelectedSample}"/>

Sorry for the horrible naming convention, but I was just trying to get a prototype working. Basically the list gets populated off a table when items are selected in a table. So the ItemsSource is that collection of Sample objects.

From my understanding (could be wrong, feel free to correct me), the DisplayMemberPath is what is to be displayed in the box. So in this case, the Sample object property is SampleName.

The SelectedValue and SelectedItem I'm not sure exactly what those are :( . What I do know, is I want to be able to have an action that when one of the Samples is selected, I change the SelectedSample (single instead of plural) property in order to update other things in my program.

Hopefully that makes sense. Any thoughts? Thanks.

Upvotes: 2

Views: 151

Answers (1)

Tim Destan
Tim Destan

Reputation: 2028

You could attach a handler to the SelectionChanged event on the ComboBox. MSDN doc

Upvotes: 1

Related Questions