DataGridView row repositioning

这一生的挚爱 提交于 2019-12-13 18:34:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!