Hi all,
I'm trying to sort the columns of a datagrid A to Z, the code below works apart from I get a column beginning with 'c' in between the 'A' (e.g. a,a,a,a,c,a,a,b,b,b), this happens the first time I run the code. If I then use columnNames.Reverse(); (Z to A) and then re-run columnNames.Sort() (A to Z) it sorts correctly. Why would this be?
List<string> columnNames = new List<string>();
foreach (DataGridViewColumn col in dataGridView1.Columns)
columnNames.Add(col.HeaderText);
columnNames.Sort();
foreach (DataGridViewColumn col in dataGridView1.Columns)
col.DisplayIndex = columnNames.IndexOf(col.HeaderText);
Thanks