问题
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.
回答1:
to move a row, use DataGridView.Rows.RemoveAt and then DataGridView.Rows.Insert
回答2:
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.
来源:https://stackoverflow.com/questions/1048334/datagridview-row-repositioning