dataGridView1 ColumnHeaderMouseCli ck obj evnt int columns dataGridVie

 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
dataGridView1.ColumnHeaderMouseClick += (obj, evnt) =>
{
int columns = dataGridView1.Columns.Count;
int[] array = _stack.Distinct().ToArray();
string sort = null;
if (array.Length == 1)
{
int i = array[0];
comsort += dataGridView1.Columns[i].HeaderText;
DataGridViewColumn gridViewColumn = dataGridView1.Columns[i];
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();
}
comsort += sort;
}
else
for (int index = array.Length - 1; index >= 0; index--)
{
int i = array[index];
string sql = dataGridView1.Columns[i].HeaderText;
if (index >= columns)
{
break;
}
DataGridViewColumn gridViewColumn = dataGridView1.Columns[i];
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();
}
if (index == 0)
comsort += sql + sort;
else
comsort += sql + sort + ",";
};
comsort += ";";
dataGridView1.DataSource = q.getTable(comsort);
};