DataGridView:如何选择整个列并取消选择其他所有内容? [英] DataGridView: How to select an entire Column and deselect everything else?
本文介绍了DataGridView:如何选择整个列并取消选择其他所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试找出如何使用鼠标右键单击+菜单+选择此列"来选择列下的所有单元格...
I've been trying to find out how to select all cells under a Column with a 'mouse right click+menu+Select this Column'...
MSDN 没有太大帮助...
MSDN isn't helping much...
当我尝试更改选择模式时出现此错误:
I get this error when I try to change selection mode:
DataGridView control's SelectionMode cannot be set to FullColumnSelect while it has a column with SortMode set to DataGridViewColumnSortMode.Automatic.
谢谢,Y_Y
推荐答案
遍历列中的单元格并将其 Selected 属性设置为 true.
这听起来很可怕,但我相信这是选择整列并保持自动排序的唯一方法.
Loop through the cells in the column and set their Selected property to true.
It sounds horrible, but I believe it's the only way to select an entire column and keep automatic sorting.
例如:
grid.ClearSelection();
for(int r = 0; r < grid.RowCount; r++)
grid[columnIndex, r].Selected = true;
这篇关于DataGridView:如何选择整个列并取消选择其他所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文