Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# DataGridView Disable sort icon from the column header

Tags:

I have a Winforms DataGridView with few columns which can be sorted and few which couldn't be. For columns which I don't want my gridview to be sorted I have set

dgvConnections.Columns[e.ColumnIndex].SortMode = DataGridViewColumnSortMode.NotSortable; in

dgvConnections_ColumnHeaderMouseClick event handler but I am unable to get rid of the the sort icon from the column header, as its presence could cause confusion to the user.

So kindly suggest me a way to get rid of the sorting icon from the column which cannot be sorted. Thanks in advance!

like image 630
pradeepradyumna Avatar asked May 15 '17 11:05

pradeepradyumna


People also ask

What is %d in C programming?

In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs.

How old is the letter C?

The letter c was applied by French orthographists in the 12th century to represent the sound ts in English, and this sound developed into the simpler sibilant s.

What does %c mean in C?

%d is used to print decimal(integer) number ,while %c is used to print character . If you try to print a character with %d format the computer will print the ASCII code of the character.


1 Answers

It looks like you are not maintaining the correct execution order. The code you wrote will do the work

dgvConnections.Columns[e.ColumnIndex].SortMode = DataGridViewColumnSortMode.NotSortable;

but make sure you are calling it after initializing the DataGridView.

If you want it for specific columns like you mentioned in your question, you need to find the index and set the sortmode.

like image 115
Karthik AMR Avatar answered Sep 24 '22 10:09

Karthik AMR