/
Form1.vb
92 lines (74 loc) · 2.92 KB
/
Form1.vb
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
Imports System
Imports System.Windows.Forms
Imports System.Data
Imports DevExpress.Data
Imports DevExpress.XtraGrid
Namespace HideableGroupRowFooters
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
myGridControl1.DataSource = CreateTable(30)
GroupColumns()
SetSummaryItems()
End Sub
Private Function CreateTable(ByVal RowCount As Integer) As DataTable
Dim tbl As New DataTable()
tbl.Columns.Add("Category", GetType(String))
tbl.Columns.Add("Vendor", GetType(String))
tbl.Columns.Add("Model", GetType(String))
tbl.Columns.Add("HasSmth", GetType(String))
tbl.Columns.Add("NumOfSmth", GetType(Integer))
For i As Integer = 0 To RowCount - 1
Dim r As Integer = (New Random(i)).Next(0, 10)
Dim hasSmth As String = If(r <= 5, "Yes", "No")
r = (New Random(i)).Next(0, 10)
Dim cat As String = If(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 })
Next i
Return tbl
End Function
Private Sub GroupColumns()
myGridView1.Columns("Category").Group()
myGridView1.Columns("Vendor").Group()
myGridView1.Columns("HasSmth").Group()
myGridView1.ExpandAllGroups()
End Sub
Private Sub SetSummaryItems()
Dim item As New GridGroupSummaryItem()
item.FieldName = "Model"
item.SummaryType = DevExpress.Data.SummaryItemType.Count
item.ShowInGroupColumnFooter = myGridView1.Columns("Model")
myGridView1.GroupSummary.Add(item)
Dim item1 As New GridGroupSummaryItem()
item1.FieldName = "NumOfSmth"
item1.DisplayFormat = "{0:f3}"
item1.SummaryType = DevExpress.Data.SummaryItemType.Average
item1.ShowInGroupColumnFooter = myGridView1.Columns("NumOfSmth")
myGridView1.GroupSummary.Add(item1)
End Sub
Private Sub gridViewOverride1_ShowGroupFooter(ByVal sender As Object, ByVal e As ShowGroupFooterEventArgs) Handles myGridView1.ShowGroupFooter
If e.FooterLevel = spinEdit1.Value AndAlso checkEdit1.Checked Then
e.Visible = False
End If
End Sub
Private Sub checkEdit1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles checkEdit1.CheckedChanged
myGridView1.LayoutChanged()
End Sub
Private Sub spinEdit1_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles spinEdit1.EditValueChanged
myGridView1.LayoutChanged()
End Sub
Private Sub gridViewOverride1_EndGrouping(ByVal sender As Object, ByVal e As EventArgs) Handles myGridView1.EndGrouping
Dim maxLevel As Integer = 0
For i As Integer = 0 To myGridView1.GroupedColumns.Count - 1
If myGridView1.GroupedColumns(i).GroupIndex > maxLevel Then
maxLevel = myGridView1.GroupedColumns(i).GroupIndex
End If
Next i
spinEdit1.Properties.MaxValue = maxLevel + 1
End Sub
End Class
End Namespace