Does WPF DataGrid fire an event when a row is added / removed?

前端 未结 7 618
失恋的感觉
失恋的感觉 2021-02-06 05:48

I wish to recalculate things everytime a DataGrid gets more rows or some are removed. I tried to use the Loaded event, but that was fired only once.

I found

7条回答
  •  忘了有多久
    2021-02-06 06:41

    I was looking for solution to this and I have found the perfect event to handle this, the event is called UnloadingRow

    
     ...
    
    

    In your C# code u get this

    private void ProductsDataGrid_UnloadingRow(object sender, DataGridRowEventArgs e)
    {
       MyObject obj = (MyObject)e.Row.Item; // get the deleted item to handle it
       // Rest of your code ...
       // For example : deleting the object from DB using entityframework
    
    }
    

提交回复
热议问题