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.
+2
A:
to move a row, use DataGridView.Rows.RemoveAt and then DataGridView.Rows.Insert
Chetan
2009-06-26 12:00:56
+1 for supplying an answer to your own question. There should be a badge for that.
TGnat
2009-06-26 12:14:53
A:
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.
Jared Updike
2010-02-08 22:20:04