/
Form1.cs
101 lines (84 loc) · 2.97 KB
/
Form1.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Windows.Forms;
using System.Data;
using DevExpress.Data;
using DevExpress.XtraGrid;
namespace HideableGroupRowFooters
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
myGridControl1.DataSource = CreateTable(30);
GroupColumns();
SetSummaryItems();
}
private DataTable CreateTable(int RowCount)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("Category", typeof(string));
tbl.Columns.Add("Vendor", typeof(string));
tbl.Columns.Add("Model", typeof(string));
tbl.Columns.Add("HasSmth", typeof(string));
tbl.Columns.Add("NumOfSmth", typeof(int));
for (int i = 0; i < RowCount; i++)
{
int r = new Random(i).Next(0, 10);
string hasSmth = r <= 5 ? "Yes" : "No";
r = new Random(i).Next(0, 10);
string cat = r <= 5 ? "Cat1" : "Cat2";
r = new Random(i).Next(0, 4);
tbl.Rows.Add(new object[] { cat, String.Format("Vendor {0}", r), String.Format("Model {0}", i), hasSmth, i });
}
return tbl;
}
private void GroupColumns()
{
myGridView1.Columns["Category"].Group();
myGridView1.Columns["Vendor"].Group();
myGridView1.Columns["HasSmth"].Group();
myGridView1.ExpandAllGroups();
}
private void SetSummaryItems()
{
GridGroupSummaryItem item = new GridGroupSummaryItem();
item.FieldName = "Model";
item.SummaryType = DevExpress.Data.SummaryItemType.Count;
item.ShowInGroupColumnFooter = myGridView1.Columns["Model"];
myGridView1.GroupSummary.Add(item);
GridGroupSummaryItem item1 = new GridGroupSummaryItem();
item1.FieldName = "NumOfSmth";
item1.DisplayFormat = "{0:f3}";
item1.SummaryType = DevExpress.Data.SummaryItemType.Average;
item1.ShowInGroupColumnFooter = myGridView1.Columns["NumOfSmth"];
myGridView1.GroupSummary.Add(item1);
}
private void gridViewOverride1_ShowGroupFooter(object sender, ShowGroupFooterEventArgs e)
{
if ( e.FooterLevel == spinEdit1.Value && checkEdit1.Checked )
e.Visible = false;
}
private void checkEdit1_CheckedChanged(object sender, EventArgs e)
{
myGridView1.LayoutChanged();
}
private void spinEdit1_EditValueChanged(object sender, EventArgs e)
{
myGridView1.LayoutChanged();
}
private void gridViewOverride1_EndGrouping(object sender, EventArgs e)
{
int maxLevel = 0;
for ( int i = 0; i < myGridView1.GroupedColumns.Count; i++ )
{
if ( myGridView1.GroupedColumns[i].GroupIndex > maxLevel )
maxLevel = myGridView1.GroupedColumns[i].GroupIndex;
}
spinEdit1.Properties.MaxValue = maxLevel + 1;
}
}
}