views:

194

answers:

2

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
+1 for supplying an answer to your own question. There should be a badge for that.
TGnat
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