I have a sorted list that contains the column headers, how do I rearrange my datagridview so it is in the same order as my sorted list?
I've tried the code below but this doesn't always work, some columns are not sorted correctly. Thanks for any help with this.
sortedColumnNames.Sort();
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
col.DisplayIndex = sortedColumnNames.IndexOf(col.HeaderText);
}
sortedColumnNames: athens crete corfu kefalonia mykonos rhodes santorini skiathos zante