Define a Datagrid WPF Column as the Source of Combobox Elements

I have a Combobox in which I would like its elements to be column data located in a DataGrid. In any case, to set the Combobox data source to a separate DataGrid column?

Now I repeat every row of the DataGrid, getting the field data and adding it to the Combobox, but this means that I will need to clear all the elements and repeat it every time the DataGrid changes.

+4
source share
2 answers

You can set the ItemsSource and DisplayMemberPath properties:

comboBox1.ItemsSource = dataGrid1.ItemsSource; comboBox1.DisplayMemberPath = "ColumnName"; 
+2
source

I think you're wrong. Your data grid should be tied to a collection of objects. I assume that you could just create another collection by extracting the fields you need (e.g. with linQ) and exposing this new collection for your view so that you can bind your drop-down lists.

I want this second collection updated, make your first primary ObservableCollection such that you can subscribe to the CollectionChanged event. In the event handler, simply control the addition and deletion of the combobox in the source collection.

0
source

All Articles