Changing values in the RowEditEnding event of a DataGrid
I have a DataGrid that has a check box column. Only one row can have the box checked. If the user checks a new box all the other boxes should automatically be unchecked, similar to a radio button. I have tried to implement that behaviour in the RowEditEnding event, but if I modify the values of the objects in this event the edit appears to be cancelled? ie The the check boxes are left unchanged. If the check box is unchecked the check boxes are updated and the edit happens normally Here is the code I am using:
private void grdQuestionAnswers_RowEditEnded(object sender, System.Windows.Controls.DataGridRowEditEndedEventArgs e)
{
if (DataGridEditAction.Commit == e.EditAction)
{
Answer answer = (Answer)e.Row.DataContext;
if (answer.Correct == true)
{
foreach (Answer otherAnswer in grdQuestionAnswers.ItemsSource)
{
if (otherAnswer != answer)
{
answer.Correct = false;
}
}
}
}
}
I am a SL noob so if there is a better way to do this I am all ears.