开发者

Changing values in RowEditEnding

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 !=开发者_StackOverflow社区 answer)
                {
                    answer.Correct = false;
                }
            }
        }
    }
}


As far as I can tell the "RowEditEnding" event serves no purpose. When it gets fired, the values in that row have not yet been changed and you can't see what they will be changed to.

"RowEditEnded" may be what you want - I ran into this problem in WPF and found out that the WPF DataGrid doesn't even have "RowEditEnded". Since I was binding to a DataTable, I just attached to the DataTable's RowChanged event.

Also -

answer.Correct = false;

should be

otherAnswer.Correct = false;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜