I have a DataGridView in my form and I am binding that DataGridView to a List.
The column is set to SortMode=Automatic.
This is my code
List<string> lstLines = new List<string>();
StreamReader sr = new StreamReader(tbFile.Text);
while ((line = sr.ReadLine()) != null)
{
lstLines.Add(line);
}
dgvLines.DataSource = lstLines.Select(x=>new {Text=x}).ToList();
When I click on column header I expected the column to be sorted but nothing happens.
you Can try this……
Complete code to sort the column of datagridview whose datasource is a generic List
//—————————————————————————————–
//In the form – In constructor or form load, populate the grid.
//——————————————————————————————–
//———————————————————————————————
//Comparer class to perform sorting based on column name and sort order
//———————————————————————————————
//———————————————————————————————
// Performing sort on click on Column Header
//———————————————————————————————
I am hoping that it will helps you…..