Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Can anybody tell me why the data in the datagrid disappear as soon as one of it's column is sorted.

I have enabled the ColumnVal.SortMode = DataGridViewColumnSortMode.Auutomatic property available for grid, but after sorting, other column data disappears. Why this happens?

Thanks & regards,
Jagadisha. N

What I have tried:

ColumnVal.SortMode = DataGridViewColumnSortMode.Automatic;
Posted
Updated 23-Jun-16 22:05pm
Comments
Karthik_Mahalingam 24-Jun-16 4:26am    
by default all columns sort mode will be Automatic
Jagadisha_Ingenious 24-Jun-16 5:14am    
Ya it will sort but data in other columns disappear why...?

1 solution

To sort a column in DataGridView , try this
foreach(DataGridViewColumn column in dataGridView1.Columns)
  {
    dataGridView1.Columns[column.Name].SortMode = DataGridViewColumnSortMode.Automatic; 
  }

Here SortMode property is Automatic
 
Share this answer
 
Comments
Jagadisha_Ingenious 24-Jun-16 5:15am    
Thanks Animesh Datta, but whhen i click on the row header to sort the sorting happens for that particular column & data in other column disappears. Why such a thing happens..?

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