I am trying to toggle the checkboxes in a DataGridCheckboxColumn if it has more than a certain number in another column.
So far, it loops through the DataGrid and succesfully validates the other column I need it to, but I cannot toggle any of the Chekboxes that meet the criteria.
<DataGridTextColumn Header="Total" IsReadOnly="True" Binding="{Binding cost}" Width="130"></DataGridTextColumn>
<DataGridCheckBoxColumn Header="Check" IsReadOnly="False" Width="50">
<DataGridCheckBoxColumn.ElementStyle>
<Style />
</DataGridCheckBoxColumn.ElementStyle>
</DataGridCheckBoxColumn>
for(int i=0; i<dataGrid.Items.Count - 1; i++)
{
if(Convert.ToDecimal(dataGrid.Columns[3].GetCellContent(i)) > 200)
{ //Columns[3] is the "Total" Column.
((dataGrid.Columns[6]).GetCellContent(i) as CheckBox).IsChecked = true;
//Columns[6] is the DataGridCheckBoxColumn
}
}
I get the correct value for the Total column using:
dataGrid.Columns[3].GetCellContent(i)
But
((dataGrid.Columns[6]).GetCellContent(i) as CheckBox);
Which is the DataGridCheckBoxColumn, returns a nullException, even though it is the right column. If I WriteLine dataGrid.Columns[6], I get "System.Windows.Controls.DataGridCheckBoxColumn", so I'm sure I'm in the right place but I cannot set it to true.