Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I put as datasource to a datagridview a List< TestUtilizator >

C#
class TestUtilizator
    {
        public string NumeTest { get; set; }
        public DateTime data { get; set; }
        public int punctaj { get; set; }

        public TestUtilizator() { }
        public TestUtilizator(string NumeTest, DateTime data, int punctaj)
        {
            this.NumeTest=NumeTest;
            this.data=data;
            this.punctaj=punctaj;

        }


I have set all columns sortmode to Automatic:
C#
foreach (DataGridViewColumn column in dataGridView1.Columns)
           {
               dataGridView1.Columns[column.Name].SortMode = DataGridViewColumnSortMode.Automatic;
           }


But when I click on the header of the column, it doesn't do anything. It should sort my data ascending or descending



Do I have to do more settings for this to work?
Thank you!
Posted
Updated 2-Feb-18 0:28am

1 solution

dataGridView1.Sort(dataGridView1.Columns(column.Name), System.ComponentModel.ListSortDirection.Ascending)

And also check the property of your datagridview
(Allow user to Order Column=True) this is set to be true
 
Share this answer
 
Comments
Luci C 13-May-13 5:40am    
thank you...I had to replace my List<t> with SortedBindingList<t> to make the sort method work..but now it works great

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