How can I rearrange the rows of a DataGridView in the code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Falkeli
    New Member
    • Feb 2012
    • 19

    How can I rearrange the rows of a DataGridView in the code?

    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:
    Code:
    dataGridView1.Rows.RemoveAt(e.Index);
    And when an element is added to the ListBox, the following code is executed:
    Code:
    dataGridView1.Rows.Insert(e.Index, row);
    Except that an exception (InvalidOperati onException) 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?
Working...