This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GridViewQuickColumnCustomization.vb
266 lines (252 loc) · 9.47 KB
/
GridViewQuickColumnCustomization.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.Utils
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.XtraEditors.Popup
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls
Imports System.Drawing
Imports DevExpress.XtraGrid.Columns
Imports System.Windows.Forms
Imports DevExpress.XtraGrid.Views.Grid.Drawing
Namespace DevExpress.XtraGrid.Helpers
Public Class GridViewQuickColumnCustomization
Private Enum ColumnCustomizationState
None
Pressed
Shown
End Enum
'INSTANT VB NOTE: The field view was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private view_Renamed As GridView
'INSTANT VB NOTE: The field state was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private state_Renamed As ColumnCustomizationState = ColumnCustomizationState.None
'INSTANT VB NOTE: The field containerEdit was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private containerEdit_Renamed As GridViewQuickColumnCustomizationContainerEdit
'INSTANT VB NOTE: The field popupSize was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private popupSize_Renamed As Size = Size.Empty
'INSTANT VB NOTE: The variable view was renamed since Visual Basic does not handle local variables named the same as class members well:
Public Sub New(ByVal view_Renamed As GridView)
Me.view_Renamed = view_Renamed
AddHandler Me.View.CustomDrawRowIndicator, AddressOf View_CustomDrawRowIndicator
AddHandler Me.View.MouseDown, AddressOf View_MouseDown
AddHandler Me.View.MouseUp, AddressOf View_MouseUp
End Sub
Public ReadOnly Property View() As GridView
Get
Return view_Renamed
End Get
End Property
Public Property PopupSize() As Size
Get
Return popupSize_Renamed
End Get
Set(ByVal value As Size)
popupSize_Renamed = value
End Set
End Property
Private Property State() As ColumnCustomizationState
Get
Return state_Renamed
End Get
Set(ByVal value As ColumnCustomizationState)
If State = value Then
Return
End If
state_Renamed = value
InvalidateIndicator()
If State = ColumnCustomizationState.Shown Then
ShowCustomization()
End If
End Set
End Property
Private Sub View_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
State = If(IsCursorOnColumnButton(e), ColumnCustomizationState.Pressed, ColumnCustomizationState.None)
End Sub
Private Sub View_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If State <> ColumnCustomizationState.Pressed Then
Return
End If
State = If(IsCursorOnColumnButton(e), ColumnCustomizationState.Shown, ColumnCustomizationState.None)
End Sub
Private Sub View_CustomDrawRowIndicator(ByVal sender As Object, ByVal e As RowIndicatorCustomDrawEventArgs)
If e.RowHandle = GridControl.InvalidRowHandle Then
' You may assign your own image list e.Info.Images to show the custom image.
e.Info.ImageIndex = GridPainter.IndicatorNewItemRow
e.Info.Appearance.ForeColor = Color.Blue
If State <> ColumnCustomizationState.None Then
e.Info.State = DevExpress.Utils.Drawing.ObjectState.Pressed
End If
End If
End Sub
Private Sub ShowCustomization()
SetupContainerEdit()
ContainerEdit.ShowPopup()
End Sub
Private Function GetColumnButtonBounds() As Rectangle
Dim vi As GridViewInfo = TryCast(View.GetViewInfo(), GridViewInfo)
For i As Integer = 0 To vi.ColumnsInfo.Count - 1
If vi.ColumnsInfo(i).Type = GridColumnInfoType.Indicator Then
Return vi.ColumnsInfo(i).Bounds
End If
Next i
Return Rectangle.Empty
End Function
Private Sub InvalidateIndicator()
View.InvalidateRect(GetColumnButtonBounds())
End Sub
Private columnButtonLoation As Point = Point.Empty
Private Function IsCursorOnColumnButton(ByVal e As System.EventArgs) As Boolean
Dim de As DXMouseEventArgs = DXMouseEventArgs.GetMouseArgs(View.GridControl, e)
Dim o As Object = View.CalcHitInfo(de.Location)
Return View.CalcHitInfo(de.Location).HitTest = GridHitTest.ColumnButton
End Function
Protected ReadOnly Property ContainerEdit() As GridViewQuickColumnCustomizationContainerEdit
Get
Return containerEdit_Renamed
End Get
End Property
Private Sub SetupContainerEdit()
Me.containerEdit_Renamed = New GridViewQuickColumnCustomizationContainerEdit(View)
ContainerEdit.Text = String.Empty
ContainerEdit.Properties.AutoHeight = False
ContainerEdit.Properties.LookAndFeel.ParentLookAndFeel = View.GridControl.LookAndFeel
ContainerEdit.Properties.Appearance.BackColor = Color.Transparent
ContainerEdit.Properties.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder
ContainerEdit.Properties.Buttons.Clear()
AddHandler ContainerEdit.Closed, AddressOf OnClosed
ContainerEdit.Bounds = GetColumnButtonBounds()
If Not PopupSize.IsEmpty Then
ContainerEdit.Properties.PopupStartSize = PopupSize
End If
ContainerEdit.Parent = View.GridControl
End Sub
Private Sub OnClosed(ByVal sender As Object, ByVal e As ClosedEventArgs)
ContainerEdit.Dispose()
Me.containerEdit_Renamed = Nothing
State = ColumnCustomizationState.None
End Sub
End Class
Public Class GridViewQuickColumnCustomizationContainerEdit
Inherits BlobBaseEdit
Private view As GridView
Public Sub New(ByVal view As GridView)
Me.view = view
End Sub
Protected Overrides Function CreatePopupForm() As PopupBaseForm
Return New GridViewQuickColumnCustomizationPopup(Me, view)
End Function
Protected Overrides Sub OnPopupClosing(ByVal e As CloseUpEventArgs)
If e.AcceptValue Then
CType(PopupForm, GridViewQuickColumnCustomizationPopup).Apply()
End If
MyBase.OnPopupClosing(e)
End Sub
End Class
Public Class GridViewQuickColumnCustomizationPopup
Inherits BlobBasePopupForm
'INSTANT VB NOTE: The field view was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private view_Renamed As GridView
'INSTANT VB NOTE: The field checkListBox was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private checkListBox_Renamed As CheckedListBoxControl
'INSTANT VB NOTE: The variable view was renamed since Visual Basic does not handle local variables named the same as class members well:
Public Sub New(ByVal ownerEdit As BlobBaseEdit, ByVal view_Renamed As GridView)
MyBase.New(ownerEdit)
Me.view_Renamed = view_Renamed
Me.checkListBox_Renamed = New CheckedListBoxControl()
Me.checkListBox_Renamed.BorderStyle = BorderStyles.Simple
Me.checkListBox_Renamed.Appearance.Assign(ownerEdit.Properties.AppearanceDropDown)
Me.checkListBox_Renamed.LookAndFeel.ParentLookAndFeel = OwnerEdit.LookAndFeel
Me.checkListBox_Renamed.Visible = False
Me.checkListBox_Renamed.CheckOnClick = True
AddHandler checkListBox_Renamed.ItemCheck, AddressOf OnCheckListBoxItemCheck
Me.Controls.Add(checkListBox_Renamed)
UpdateCheckListBox()
FillList()
OkButton.Enabled = True
End Sub
Public Sub Apply()
View.BeginUpdate()
Try
For i As Integer = 0 To CheckListBox.Items.Count - 1
Dim column As GridColumn = CType(CheckListBox.Items(i).Value, GridColumn)
column.Visible = CheckListBox.Items(i).CheckState = CheckState.Checked
Next i
Finally
View.EndUpdate()
End Try
End Sub
Protected ReadOnly Property View() As GridView
Get
Return view_Renamed
End Get
End Property
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If CheckListBox IsNot Nothing Then
Me.checkListBox_Renamed.Dispose()
Me.checkListBox_Renamed = Nothing
End If
End If
MyBase.Dispose(disposing)
End Sub
Protected Overrides ReadOnly Property EmbeddedControl() As Control
Get
Return CheckListBox
End Get
End Property
Public ReadOnly Property CheckListBox() As CheckedListBoxControl
Get
Return checkListBox_Renamed
End Get
End Property
Protected Sub UpdateCheckListBox()
OkButton.Enabled = True
CheckListBox.BeginUpdate()
Try
CheckListBox.Appearance.Assign(ViewInfo.PaintAppearanceContent)
Finally
CheckListBox.EndUpdate()
End Try
End Sub
Public Overrides Sub ProcessKeyDown(ByVal e As KeyEventArgs)
If e.KeyCode = Keys.Enter Then
e.Handled = True
OwnerEdit.ClosePopup()
Return
End If
MyBase.ProcessKeyDown(e)
End Sub
Public Overrides Sub ShowPopupForm()
BeginControlUpdate()
Try
UpdateCheckListBox()
Finally
EndControlUpdate()
End Try
MyBase.ShowPopupForm()
FocusFormControl(CheckListBox)
OkButton.Enabled = True
End Sub
Private Sub FillList()
CheckListBox.BeginUpdate()
Try
For Each column As GridColumn In View.Columns
If column.OptionsColumn.ShowInCustomizationForm Then
CheckListBox.Items.Add(column, column.GetTextCaption(),If(column.Visible, CheckState.Checked, CheckState.Unchecked), True)
End If
Next column
Finally
CheckListBox.EndUpdate()
End Try
End Sub
Private Sub OnCheckListBoxItemCheck(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ItemCheckEventArgs)
Dim hasVisibleButton As Boolean = False
For i As Integer = 0 To CheckListBox.Items.Count - 1
If CheckListBox.Items(i).CheckState = System.Windows.Forms.CheckState.Checked Then
hasVisibleButton = True
Exit For
End If
Next i
OkButton.Enabled = hasVisibleButton
End Sub
End Class
End Namespace