This must be simple but all my searching leads to binding-based solutions, which is not my case.
I have a DataGrid
in which there is a DataGridComboBoxColumn
. This column's ItemsSource
property is bound to a string array. I use a loop in the startup to set the SelectedItem
of 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 particular cell of this column, the dropdown appears in the cell and is correctly populated with all array items, but the dropdown's current text is empty, i.e. it doesn't automatically select the corresponding item from the dropdown. What am I missing?
EDIT
Here is the relevant portion 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 bound to an underlying DataColumn
or something, although the whole DataGrid IS bound to a DataTable. Also, I know for sure that this is not a spelling issue.