This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
CustomGridControl.vb
210 lines (199 loc) · 7.61 KB
/
CustomGridControl.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Grid.Drawing
Imports DevExpress.XtraGrid.Registrator
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.Utils
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.XtraGrid.Columns
Imports System.ComponentModel
Namespace GridView_PriorityRowCellStyle
Public Class CustomGridView
Inherits GridView
Private priorityStyleEventArgs As New PriorityRowCellStyleEventArgs(Nothing, New AppearanceObject(), False)
Public Sub New()
MyBase.New()
End Sub
Protected Friend Overridable Sub SetGridControlAccessMetod(ByVal newControl As GridControl)
SetGridControl(newControl)
End Sub
Private Shared ReadOnly _priorityRowCellStyle As Object = New Object()
Public Overrides Sub Assign(ByVal v As BaseView, ByVal copyEvents As Boolean)
If v Is Nothing Then
Return
End If
BeginUpdate()
Try
Dim gv As CustomGridView = TryCast(v, CustomGridView)
If gv IsNot Nothing Then
If copyEvents Then
Events.AddHandler(_priorityRowCellStyle, gv.Events(_priorityRowCellStyle))
End If
End If
Finally
EndUpdate()
End Try
End Sub
<Description("Enables the appearance settings of individual cells to be changed, or merged with Format Conditon"), Category("Appearance")> _
Public Custom Event PriorityRowCellStyle As PriorityRowCellStyleEventHandler
AddHandler(ByVal value As PriorityRowCellStyleEventHandler)
Me.Events.AddHandler(_priorityRowCellStyle, value)
End AddHandler
RemoveHandler(ByVal value As PriorityRowCellStyleEventHandler)
Me.Events.RemoveHandler(_priorityRowCellStyle, value)
End RemoveHandler
RaiseEvent(ByVal sender As Object, ByVal e As PriorityRowCellStyleEventArgs)
End RaiseEvent
End Event
Protected Friend Overridable Function RaisePriorityRowCellStyle(ByVal cellInfo As GridCellInfo, ByVal appearance As AppearanceObject, ByVal overrydeFormatCondition As Boolean) As AppearanceObject
priorityStyleEventArgs.OverrydeFormatCondition = False
Dim handler As PriorityRowCellStyleEventHandler = CType(Events(_priorityRowCellStyle), PriorityRowCellStyleEventHandler)
If handler Is Nothing Then
Return appearance
End If
priorityStyleEventArgs.Appearance = TryCast(appearance.Clone(), AppearanceObject)
priorityStyleEventArgs.SetCellInfo(cellInfo)
handler(Me, priorityStyleEventArgs)
Return priorityStyleEventArgs.Appearance
End Function
Protected Overrides ReadOnly Property ViewName() As String
Get
Return "CustomGridView"
End Get
End Property
Protected Friend Overridable Function GetPriorityRowCellStyle(ByVal cellInfo As GridCellInfo, ByVal appearance As AppearanceObject) As AppearanceObject
Return RaisePriorityRowCellStyle(cellInfo, appearance, False)
End Function
Protected Friend Overridable ReadOnly Property OverrideFormatCondition() As Boolean
Get
Return priorityStyleEventArgs.OverrydeFormatCondition
End Get
End Property
End Class
Public Delegate Sub PriorityRowCellStyleEventHandler(ByVal sender As Object, ByVal e As PriorityRowCellStyleEventArgs)
Public Class PriorityRowCellStyleEventArgs
Inherits EventArgs
Private overrydeFormatCondition_Renamed As Boolean
Private cellInfo_Renamed As GridCellInfo
Private appearance_Renamed As AppearanceObject
Public Sub New(ByVal cellInfo As GridCellInfo, ByVal appearance As AppearanceObject, ByVal overrydeFormatCondition As Boolean)
MyBase.New()
Me.overrydeFormatCondition_Renamed = overrydeFormatCondition
Me.cellInfo_Renamed = cellInfo
Me.appearance_Renamed = appearance
End Sub
Public Property OverrydeFormatCondition() As Boolean
Get
Return overrydeFormatCondition_Renamed
End Get
Set(ByVal value As Boolean)
overrydeFormatCondition_Renamed = value
End Set
End Property
Public ReadOnly Property CellInfo() As GridCellInfo
Get
Return cellInfo_Renamed
End Get
End Property
Protected Friend Sub SetCellInfo(ByVal cellInfo As GridCellInfo)
Me.cellInfo_Renamed = cellInfo
End Sub
Public Property Appearance() As AppearanceObject
Get
Return appearance_Renamed
End Get
Set(ByVal value As AppearanceObject)
appearance_Renamed = value
End Set
End Property
End Class
Public Class CustomGridControl
Inherits GridControl
Public Sub New()
MyBase.New()
End Sub
Protected Overrides Sub RegisterAvailableViewsCore(ByVal collection As InfoCollection)
MyBase.RegisterAvailableViewsCore(collection)
collection.Add(New CustomGridInfoRegistrator())
End Sub
Protected Overrides Function CreateDefaultView() As BaseView
Return CreateView("CustomGridView")
End Function
End Class
Public Class CustomGridInfoRegistrator
Inherits GridInfoRegistrator
Public Sub New()
MyBase.New()
End Sub
Public Overrides ReadOnly Property ViewName() As String
Get
Return "CustomGridView"
End Get
End Property
Public Overrides Function CreateView(ByVal grid As GridControl) As BaseView
Dim view As New CustomGridView()
view.SetGridControlAccessMetod(grid)
Return view
End Function
Public Overrides Function CreateViewInfo(ByVal view As BaseView) As DevExpress.XtraGrid.Views.Base.ViewInfo.BaseViewInfo
Return New CustomGridViewInfo(TryCast(view, GridView))
End Function
End Class
Public Class CustomGridViewInfo
Inherits GridViewInfo
Public Sub New(ByVal gridView As GridView)
MyBase.New(gridView)
End Sub
Protected Overrides Sub UpdateCellAppearanceCore(ByVal cell As GridCellInfo)
MyBase.UpdateCellAppearanceCore(cell)
If cell.IsDataCell Then
If (cell.State And GridRowCellState.FocusedCell) = 0 OrElse (Not View.IsEditing) Then
Dim condition As AppearanceObjectEx = Nothing
Dim priorityStyle As AppearanceObject = (CType(View, CustomGridView)).GetPriorityRowCellStyle(cell, cell.Appearance)
If priorityStyle IsNot cell.Appearance Then
If Not(CType(View, CustomGridView)).OverrideFormatCondition Then
condition = cell.RowInfo.ConditionInfo.GetCellAppearance(cell.Column)
If condition IsNot Nothing Then
priorityStyle = MergeAppearences(priorityStyle, condition, cell.Appearance)
End If
End If
cell.Appearance = priorityStyle
End If
End If
End If
End Sub
Protected Overridable Function MergeAppearences(ByVal target As AppearanceObject, ByVal source As AppearanceObject, ByVal current As AppearanceObject) As AppearanceObject
If source.Options.UseBackColor Then
If (Not source.BackColor.IsEmpty) AndAlso source.BackColor = current.BackColor Then
target.BackColor = source.BackColor
End If
If (Not source.BackColor2.IsEmpty) AndAlso source.BackColor2 = current.BackColor2 Then
target.BackColor2 = source.BackColor2
End If
End If
If source.Options.UseBorderColor AndAlso source.BorderColor = current.BorderColor Then
target.BorderColor = source.BorderColor
End If
If source.Options.UseFont AndAlso source.Font Is current.Font Then
target.Font = source.Font
End If
If source.Options.UseForeColor AndAlso source.ForeColor = current.ForeColor Then
target.ForeColor = source.ForeColor
End If
If source.Options.UseImage And source.Image Is current.Image Then
target.Image = source.Image
End If
If source.Options.UseTextOptions AndAlso source.TextOptions Is current.TextOptions Then
target.TextOptions.Assign(source.TextOptions)
End If
If source.GradientMode = current.GradientMode Then
target.GradientMode = source.GradientMode
End If
Return target
End Function
End Class
End Namespace