Reputation: 1567
Is there a simple way to swap the position of two rows in an unbound DataGridView? I am using it to display an ordered list, where I want the up/down arrow keys to shuffle a row up and down the grid, but I can't see any way to reposition a row within the grid without completely repopulating it, which seems excessive. The Index value for a row is read-only.
Upvotes: 1
Views: 1134
Reputation: 7277
If you have data bound via BindingSource (and you store the binding source in a variable called bindingSource), you can call bindingSource.RemoveAt(x) and bindingSource.insert(x) and the data (for example, your List) and the rows of the DataGridView will swap for you.
Upvotes: 0
Reputation: 1567
to move a row, use DataGridView.Rows.RemoveAt and then DataGridView.Rows.Insert
Upvotes: 4