i am using the EF and the MVVM approach to get a bunch of data records in an ObservableCollection
. This ObservableCollection
lives in a ViewModel. The ViewModel
is than bound to a DataGrid
. This works just fine.
For the sake of data consistency i now want to turn a bunch of columns in the DataGrid
into ComboBoxes
. So the user can only choose from a predefined set of values. These predefined values are also stored in the database (You can think of it as a lookup table). I can load the values from the database and also put it in an ObservableCollection
. But now i wonder how can i bind this to the DataGrid
, since i can only specify one ItemSource
for the DataGrid
. Is this even the right approach in WPF?
Bind the ItemsSource
property of DataGridComboBoxColumn
to your values from the lookup table.
Then bind SelectedValueBinding
to the field in the main collection.
If you are using normalised values (ie numeric values mapped to the items in the lookup table), then you should also set the SelectedValuePath
and DisplayMemberPath
properties.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.