Error while clearing a Datagrid

Asked

Viewed 49 times

0

After I saved my items that are on Datagrid in a database, I would like you to clean up. So I used it as follows:

dg.Items.Clear();

But from there comes that mistake:

Operation is not Valid while Itemssource is in use. Access and Modify Elements with Itemscontrol.Itemssource Instead.

Is it being used or something? How to solve this?

  • Put the rest of the code, as you are doing to assign the ItemsSource

1 answer

1


You’ve tried it here:

dg.ItemsSource = null;
dg.Items.Refresh();
  • That way it worked. But I was thinking, this is good practice right? and I will not have problem at the time of add or make any changes?

  • I don’t know if it’s best practice, but that way you clear the reference to source previous and is free for the rest.

  • Thank you very much :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.