0

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;
    }
Cass
  • 537
  • 1
  • 7
  • 24
  • maybe this can help. http://stackoverflow.com/questions/19003133/wpf-datagrid-combobox-column – McNets Nov 12 '16 at 22:55
  • You have to work with a `DataTable` and not with a collection class (for example : `ObservableCollection`)? – FoggyFinder Nov 12 '16 at 23:59
  • #Foggy Finder -- How do I do comboboxes with a datatable? – Cass Nov 13 '16 at 02:19
  • I have it working the way I want, except for one thing. When I click the combobox field the first click highlights the cell, the second click shows the down arrow to show it is a dropdown and then the third click actucal expands the combobox. How do I get the combobox to expand on the first click? – Cass Nov 14 '16 at 01:38

0 Answers0