To get the currently displayed value from a WPF combobox, I am getting GetSelectedItem
(which gives me a dataRowView
since my itemSource
is a DataView
) and then get开发者_运维问答ting the appropriate column.
I was hoping there could be straightforward way to get the Display Value like how we have the SelectedValue
property.
Is anyone aware of a better approach?
You use the ADO.Net class DataTable, right?
You can set a displayed value quite straightforward:
<ComboBox x:Name="myComboBox" ItemsSource="{Binding}" DisplayMemberPath="SomeColumn"
SelectedValuePath="SomeColumn"/>
In this example the combobox displays the value of the column SomeColumn
. Put a correct column name instead of this dummy one.
And in code-behind:
myComboBox.DataContext = myDataSet.Customers; //any table
var selectedValue = myComboBox.SelectedValue; //The displayed value (SomeColumn)
var fullRow = myComboBox.SelectedITem; //dataRowView, I think
精彩评论