string ColumnName table Columns ColumnIndex ColumnName string AllSort

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
string ColumnName = table.Columns[e.ColumnIndex].ColumnName;
string AllSort = "";
bool cond = true;
for (int i = 0; i < Sort.Count; i++)
{
if (Sort[i] == ColumnName + " DESC")
{
Sort.RemoveAt(i);
cond = false;
break;
}
if (Sort[i] == ColumnName)
{
Sort[i] += " DESC";
cond = false;
break;
}
}
if (cond)
{
Sort.Add(ColumnName);
}
for (int i = 0; i < Sort.Count; i++)
{
AllSort += Sort[i];
if (i != Sort.Count - 1) AllSort += ",";
}
bindingSource1.Sort = AllSort;