When trying to delete specific rows from the WPF grid I get this error when I execute this command:
grid_name.Items.RemoveAt(<position of row to delete>);
The error is: Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.
When I try deleting row 2 or greater from the datatable I get an error message saying that I've tried deleting an entry in the datatable that does not exist. Essentially an out of bounds error. Strangely enough I can delete the first row.
If I break the association between the grid and the datatable by doing this I can delete whatever row I want.
grid_name.ItemsSource = null;
datatable_name.Rows.RemoveAt(<position of row to delete>);
grid_name.ItemsSource = dataset_name.Tables.DefaultView; // I only have 1 datatable in the dataset.
Is this the correct way to delete stuff from the grid?