C# – WPF DataGrid – CellEditEnding event update data

cdatagridnetwpf

I am struggling with the DataGrid in WPF. I have a ObservableCollection bound to it. When the user enters the first cell, the other cells will update accordingly. To achieve that, I subscribed to the CellEditEnding event to force the update after the first cell has been changed.

In this event, I also update other properties of MyClass like this:

    private void DataGridTeilnehmer_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
    {
        if (!commiting)
        {
          commiting = true;
            DataGridTeilnehmer.CommitEdit(DataGridEditingUnit.Row, false);
            commiting = false;

            if (e.Column.DisplayIndex == 0)
            {
                MyClass data = (e.Column.GetCellContent(e.Row) as ContentPresenter).Content as MyClass;
                data.pass = "nothing";
            }
        }

The problem is, that the Grid doesn't update itself so "nothing" is not be showed, until I enter edit-mode of the cell that is bound to the property "pass" which contains "nothing". But I would like to show it immediately.

Thanks in advance,
Frank

PS: I have worked with many (Data)Grids in my life, but the WPF Grid is the worst I encountered so far.

Best Answer

The correct way is as follows, currently use this way in my software

private void MyWPFFrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
    {
        if (e.Column.SortMemberPath.Equals("EndDate"))
        {
            if (((MyObject)e.Row.Item).EndDate.Equals(DateTime.MinValue))
            {
                ((MyObject)e.Row.Item).Completed = 1;
                ((MyObject)e.Row.Item).CompletedDescription = "YES";
            }
            else
            {
                ((MyObject)e.Row.Item).Completed = 0;
                ((MyObject)e.Row.Item).CompletedDescription = "NO";
            }


            this.MyWPFFrid.CurrentItem = ((MyObject)e.Row.Item);



            if (!e.Row.IsEditing)
            {
                this.MyWPFFrid.Items.Refresh();
            }


        }
    }
Related Topic