Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

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

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 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.

Thanks, Y_Y

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...