I am in a need of using DataGridComboboxColumn
in my dataGrid.
But the observable collection I am going to bind to my datagrid is not static ?
is it necessary for that Observale collection to be static since the data grid contains a DataGridComboboxColumn
.
What I am going to bind to the DataGridCombobox
column is another collection contained in the class of which objects are there in the observable collection I mentioned above. This is the first time I am using DataGridCombobox column. Any explanation will be much appreciated.
<DataGrid ItemSource="{Binding SomeData}">
<DataGrid.Columns>
<DataGridTemplateColumn DisplayMemberPath="FirstName" />
<DataGridTemplateColumn DisplayMemberPath="LastName" />
<DataGridComboboxColumn ItemSource={Binding SomeOtherListContainedInSomeDataAbove}" />
</DataGrid.Columns>
<DataGrid>
But this generates binding errors and says that SomeOtherListContainedInSomeDataAbove cannot be found.
pls help.
DataGridComboboxColumn
does not Participate in Logical Tree and hence it hard to do bind for itsItemsSource
Directly. ButDataGridCell
is part of the Logical Tree. You can Create an Element Style and try to bind your collection. In the below sample I have given two approaches usingDataGridComboBoxColumn
andDatagridTemplateColumn
. I am assuming you are using MVVM.Have you tried :
If your context for the binding is the
SomeData
, this should point it to the right property)From MSDN:
So, if it's not static, I'd say try option 3 :)