Roberto Salemi

Roberto Salemi

  • NA
  • 146
  • 137.8k

[WPF] DataGrid and Refresh during AddNew o EditItem

May 12 2015 6:19 AM
Hi,
in my DataGrid, the user can add a new row with a button that add an empty item in collection that is in bind with DataGrid.

The first column of DataGrid is a CheckBox Column, if the user add a NewRow and click on CheckBox Column for select/deselect all items I have an error:

"'Refresh' non consentito durante una transazione AddNew o EditItem."

My code is:
private void HeadCheck(object sender, RoutedEventArgs e, bool IsChecked)
{
var items = dgPlan.Items.OfType<AnalysisPlanItemExt>();
foreach (var item in items)
{
item.IsChecked = IsChecked;
}

try
{
dgPlan.Items.Refresh();
}
catch (Exception ex)
{
dgPlan.CancelEdit(DataGridEditingUnit.Row);
dgPlan.Items.Refresh();
}
}
I added a try-catch but the error there is still.

Thanks.

Answers (1)