Answer the question
In order to leave comments, you need to log in
How to get changed object when editing row in DataGrid WPF?
I change the line in the DataGrid, then I transfer the focus to another line, the RowEditEnding event is called in the DataGrid, but the old object comes in the parameters without changes.
Binding data to DataGrid:
var myObjectList = new List<MyObject>();
/* Заполняю список */
myObjectDataGrid.ItemsSource = myObjectList;
private void MyObjectDataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
var myObjectRow = e.Row.Item as MyObject; //Сюда приходит объект без изменений
}
Answer the question
In order to leave comments, you need to log in
The answer is found, in the XAML markup in the binding, you need to add the UpdateSourceTrigger=PropertyChanged property i.e. I had this:
and you need to do it like this:
<DataGrid x:Name="HistoryDataGrid" RowEditEnding="HistoryDataGrid_RowEditEnding" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Action, UpdateSourceTrigger=PropertyChanged}" Header="Действие"/>
<DataGridTextColumn Binding="{Binding Person, UpdateSourceTrigger=PropertyChanged}" Header="Персона"/>
<DataGridTextColumn Binding="{Binding Date, UpdateSourceTrigger=PropertyChanged}" Header="Дата"/>
</DataGrid.Columns>
</DataGrid>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question