I have created a wpf application and I am calling a window to display database table fieldnames. I am currently using a datagrid to display the field names. I would like the second column of the datagrid to be a combobox with the items "Include" and "Exclude". I know how to do the datagrid and display the field names. I cannot figure out how to do this. I do not know where to go from here.
My XML so far looks like this:
<DataGrid HeadersVisibility="Column" IsReadOnly="True" ItemsSource="{Binding}" Name="dtGrid" Loaded="GridLoaded" Width="283" HorizontalAlignment="Left" VerticalAlignment="Top" Height="365" Margin="54,74,0,0" BorderThickness="1" BorderBrush="Black">
<DataGrid.Columns>
<DataGridTextColumn x:Name="FieldName" Header="Field Name" Width="180" />
<DataGridComboBoxColumn x:Name="ComboBoxColumn" Width="83" Header="Include Field" SelectedItemBinding="{Binding strFieldInclude}" />
</DataGrid.Columns>
</DataGrid>
My code attempt looks like this:
private void DisplayFields(string[] stringFieldNames)
{
int intDisplayCnt, intTotalRowSize = 0;
string strData, strFieldSize = "";
DataTable dt = new DataTable();
dt.Columns.Add("FieldName", typeof(string));
//DataTable dt = (DataTable)dtGrid.ItemsSource;
for (intDisplayCnt = 0; intDisplayCnt < stringFieldNames.Length; intDisplayCnt++)
{
dt.Rows.Add(stringFieldNames[intDisplayCnt]);
}
dtGrid.ItemsSource = dt.DefaultView;
strFieldIncludeList = new ObservableCollection<string>() { "Include", "Exclude" };
ComboBoxColumn.ItemsSource = strFieldIncludeList;
}