I used a variant based on the WPF example to make the whole line and it worked !:
(sender as DataGrid).RowEditEnding -= DataGrid_RowEditEnding; foreach (var textColumn in dataGrid2.Columns.OfType<DataGridTextColumn>()) { var binding = textColumn.Binding as Binding; if (binding != null) { var boundItem = dataGrid2.CurrentCell.Item; var propertyName = binding.Path.Path; var propInfo = boundItem.GetType().GetProperty(propertyName); propInfo.SetValue(boundItem, NEWVALUE, new object[] { }); } } (sender as DataGrid).RowEditEnding += DataGrid_RowEditEnding;
PS: Make sure that you are using value types valid for the column (possibly using the switch statement).
e.g .: switch on propertyName or propInfo ... propInfo.SetValue (boundItem, (type) NEWVALUE, new object [] {});
switch (propertyName) { case "ColumnName": propInfo.SetValue(boundItem, ("ColumnName" type) NEWVALUE, new object[] { }); break; default: break; }
source share