-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyGridControl.vb
127 lines (114 loc) · 4.13 KB
/
MyGridControl.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports DevExpress.XtraGrid
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Registrator
Imports DevExpress.XtraGrid.Views.Printing
Imports DevExpress.Utils
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.XtraGrid.Drawing
Imports System.Collections.Generic
Namespace DXSample
Public Class MyGridControl
Inherits GridControl
Public Sub New()
MyBase.New()
End Sub
Protected Overrides Sub RegisterAvailableViewsCore(ByVal collection As InfoCollection)
MyBase.RegisterAvailableViewsCore(collection)
collection.Add(New MyGridViewInfoRegistrator())
End Sub
End Class
Public Class MyGridView
Inherits GridView
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal grid As GridControl)
MyBase.New(grid)
End Sub
Friend Const MyGridViewName As String = "MyGridView"
Protected Overrides ReadOnly Property ViewName() As String
Get
Return MyGridViewName
End Get
End Property
Protected Overrides Function CreatePrintInfoInstance(ByVal args As PrintInfoArgs) As BaseViewPrintInfo
Return New MyGridViewPrintInfo(args)
End Function
End Class
Public Class MyGridViewInfoRegistrator
Inherits GridInfoRegistrator
Public Sub New()
MyBase.New()
End Sub
Public Overrides ReadOnly Property ViewName() As String
Get
Return MyGridView.MyGridViewName
End Get
End Property
Public Overrides Function CreateView(ByVal grid As GridControl) As BaseView
Return New MyGridView(grid)
End Function
End Class
Public Class MyGridViewPrintInfo
Inherits GridViewPrintInfo
Public Sub New(ByVal args As PrintInfoArgs)
MyBase.New(args)
End Sub
Protected Overridable Sub DrawGroupTextBrick(ByVal graph As IBrickGraphics, ByVal bounds As Rectangle, ByVal rowHandle As Integer)
Dim prefFormat As String = View.GroupFormat
View.GroupFormat = "{0}:{1}"
Dim groupText As String = View.GetGroupRowDisplayText(rowHandle)
View.GroupFormat = prefFormat
Dim groupTextBounds As New Rectangle(bounds.X + Indent, bounds.Y, (CType(Columns(0), PrintColumnInfo)).Bounds.Width \ 2 - Indent, bounds.Height)
DrawTextBrick(graph, groupText, groupTextBounds, False)
For i As Integer = 0 To Columns.Count - 1
Dim col As PrintColumnInfo = CType(Columns(i), PrintColumnInfo)
Dim groupCellBounds As Rectangle = col.Bounds
groupCellBounds.Y = bounds.Y
groupCellBounds.Height = bounds.Height
If i = 0 Then
groupCellBounds.X = groupCellBounds.Width \ 2
groupCellBounds.Width -= groupCellBounds.Width \ 2
End If
Dim summary As GridGroupSummaryItem
Dim summaryText As String = String.Empty
If printSummaryInfo.TryGetValue(col.Column.FieldName, summary) Then
summaryText = View.GetGroupSummaryDisplayText(rowHandle, summary)
End If
Dim summaryBrick As ITextBrick = CType(DrawTextBrick(graph, summaryText, groupCellBounds, False), ITextBrick)
If summary IsNot Nothing AndAlso View.Columns(summary.FieldName).VisibleIndex = 0 Then
summaryBrick.HorzAlignment = HorzAlignment.Far
End If
summaryBrick.Padding = New PaddingInfo(5, 2, 0, 0)
Next i
End Sub
Protected Overrides Sub PrintGroupRow(ByVal rowHandle As Integer, ByVal level As Integer)
Dim r As Rectangle = Rectangle.Empty
r.X = Indent + level * ViewViewInfo.LevelIndent
r.Width = Me.fMaxRowWidth - r.Left
r.Y = Y
r.Height = CurrentRowHeight
SetDefaultBrickStyle(Graph, Bricks("GroupRow"))
DrawGroupTextBrick(Graph, r, rowHandle)
Y += r.Height
End Sub
Public Overrides Sub PrintRows(ByVal graph As BrickGraphics)
PreparePrintSummaryInfo()
MyBase.PrintRows(graph)
End Sub
Private printSummaryInfo As New Dictionary(Of String, GridGroupSummaryItem)()
Private Sub PreparePrintSummaryInfo()
printSummaryInfo.Clear()
For Each item As GridGroupSummaryItem In View.GroupSummary
If item.ShowInGroupColumnFooter Is Nothing AndAlso String.IsNullOrEmpty(item.ShowInGroupColumnFooterName) Then
printSummaryInfo.Add(item.FieldName, item)
End If
Next item
End Sub
End Class
End Namespace