I have a DataGridView of WinForms, and I want to be able to rearrange the rows using a ListBox located elsewhere. So when I remove an entry from the ListBox, the following line is run:
- dataGridView1.Rows.RemoveAt(e.Index);
And when an element is added to the ListBox, the following code is executed:
- dataGridView1.Rows.Insert(e.Index, row);
Except that an exception (InvalidOperationException) is thrown since the row is in the DataGridView. When I tried to wrap this line with a try block with an empty catch, the row was clearly not there. Any ideas on how to solve this?