DataGridView: How to select an entire Column and deselect everything else?

后端 未结 2 492
轮回少年
轮回少年 2020-12-19 09:17

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 isn\'t helping much...

I ge

2条回答
  •  难免孤独
    2020-12-19 10:15

    Sorry it took so long - I wanted to test before I answered, so I plopped this into Visual Studio to test first.

    I had to do this in mine to get it to work:

    foreach (DataGridViewColumn c in dataGridView1.Columns)
    {
       c.SortMode = DataGridViewColumnSortMode.NotSortable;
       c.Selected = false;
    }
    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullColumnSelect;
    dataGridView1.Columns[0].Selected = true;
    

提交回复
热议问题