簡體   English   中英

WPF DataGrid-CellEditEnding事件更新數據

[英]WPF DataGrid - CellEditEnding event update data

我在WPF中使用DataGrid感到困難。 我有一個綁定的ObservableCollection。 當用戶進入第一個單元格時,其他單元格將相應更新。 為此,我訂閱了CellEditEnding事件,以在更改第一個單元格后強制進行更新。

在這種情況下,我還像這樣更新MyClass的其他屬性:

    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";
            }
        }

問題是,直到我進入綁定到包含“ nothing”的屬性“ pass”的單元格的編輯模式,網格才會自動更新,因此不會顯示“ nothing”。 但我想立即展示。

提前致謝,
坦率

PS:我一生中曾使用過許多(數據)網格,但是WPF網格是迄今為止我遇到的最糟糕的網格。

正確的方式如下,目前在我的軟件中使用這種方式

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();
            }


        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM