I have datagrid with two columns: text and combobox. And combobox should have binding to observable collection.
This is pseudocode for datagrid items source:
public class ModeObjectState
{
public int ID { get; set; }
public int ObjectTypeID { get; set; }
public string State { get; set; }
}
public class ModeObject
{
public string Name { get; set; }
public int objID { get; set; }
public int Type { get; set; }
public int StateID { get; set; }
public bool Format { get; set; }
}
public class _dataContext
{
public ObservableCollection<ModeObjectState> ListObjectState { get; set; }
public ModeObject ModeObj { get; set; }
}
ObservableCollection<_dataContext> SourceObjList
objTable.ItemsSource = SourceObjList;
This is xaml code for datagrid:
<DataGrid x:Name="objTable" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn x:Name="ColumnName" Binding="{Binding Path=ModeObj.Name}" IsReadOnly="True" />
<DataGridComboBoxColumn x:Name="ColumnState" ItemsSource="{Binding ListObjectState}" DisplayMemberPath="State" SelectedValuePath="ID" SelectedValueBinding="{Binding Path=ModeObj.StateID}" />
</DataGrid.Columns>
</DataGrid>
But datagrid doesn't show any items in comboboxcolumn. Please, help me with binding the datagridcombobox to observable collection "ListObjectState" in "_dataContext" class.
Thanks!