It should be simple, but all my searches lead to binding solutions, which is not my case.
I have a DataGrid that has a DataGridComboBoxColumn . This property of the ItemsSource column is bound to an array of rows. I use the startup loop to set the SelectedItem this column for each row of my DataGrid through this code:
for (int i = 0; i < dgResults.Items.Count; i++) { var x = dgResults.GetCell(i, 0).Content as System.Windows.Controls.ComboBox; x.SelectedItem = "One of the items of my array"; }
GetCell() is an extension method that I grabbed from here .
Now the problem is that when I click on a specific cell of this column, the drop-down menu appears in the cell and is correctly filled with all elements of the array, but the current text of the drop-down text is empty, i.e. it does not automatically select the appropriate item from the drop-down list. What am I missing?
EDIT
Here is the relevant part of my DataGrid:
<DataGrid x:Name="dgResults" AutoGenerateColumns="False" > <DataGrid.Columns> <DataGridComboBoxColumn ItemsSource="{StaticResource ReminderValues }" /> </DataGrid.Columns> </DataGrid>
As you can see, this particular column is not associated with the underlying DataColumn or something, although the entire DataGrid IS is bound to a DataTable. In addition, I know for sure that this is not a spelling problem.
source share