Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Note it is windows application.

Disable the column sorting in DataGridView using csharp in windows application.

My code as follows,

In The Form Load I Written The Below Code as follows.
for (int i = 0; i < DGVCourseDetails.ColumnCount; i++)
{
DGVCourseDetails.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}


the above code is not working.

what is the problem, in my code.

the error shows as follows,
Index was out of range.Must be non negative and less than the size of collection parameter name index.


Please help me.

Note it is windows application.

Thanks and Regards,
Narasiman P
Posted
Comments
Surendra0x2 22-Feb-13 3:29am    
http://www.codeproject.com/Questions/550722/Howplustoplusdisableplusthepluscolumnplusheaderplu

check this link

1 solution

HI,

Try like this:

C#
protected override void OnColumnAdded(DataGridViewColumnEventArgs e)
      {
          base.OnColumnAdded(e);
          e.Column.SortMode = DataGridViewColumnSortMode.NotSortable;
      }



Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900