private readonly Stack int _stack new Stack int dataGridView1 ColumnHe

 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
34
35
private readonly Stack<int> _stack = new Stack<int>();
dataGridView1.ColumnHeaderMouseClick += (obj, evnt) =>
{
_stack.Push(evnt.ColumnIndex);
int columns = dataGridView1.Columns.Count;
int[] array = _stack.Distinct().ToArray();
var builder = new StringBuilder();
for (int index = 0; index < array.Length; index++)
{
int i = array[index];
if (index >= columns)
{
break;
}
DataGridViewColumn gridViewColumn = dataGridView1.Columns[i];
string sort = null;
switch (gridViewColumn.HeaderCell.SortGlyphDirection)
{
case System.Windows.Forms.SortOrder.None:
case System.Windows.Forms.SortOrder.Ascending:
sort = "ASC";
break;
case System.Windows.Forms.SortOrder.Descending:
sort = "DESC";
break;
default:
throw new ArgumentOutOfRangeException();
}
builder.AppendFormat("{0} {1}, ", gridViewColumn.Name, sort);
}
string s = builder.ToString();
s = s.Remove(s.Length - 2);
Console.WriteLine(s);
};