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
/
CustomGridControl.vb
84 lines (75 loc) · 3.56 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
Imports DevExpress.Utils.Drawing
Imports DevExpress.XtraEditors.Drawing
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Registrator
Imports DevExpress.XtraGrid.Views.Base
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Linq
Imports System.Windows.Forms
Namespace GridWithFilterPanelButtons
<ToolboxItem(True)> _
Public Class CustomGridControl
Inherits GridControl
Private gridControlView As CustomGridControlView
Private gridControlViewInfo As CustomGridControlViewInfo
Private Function CheckMousePositionAndSetState(ByVal mousePosition As Point, ByVal state As ObjectState) As EditorButtonObjectInfoArgs
If gridControlViewInfo IsNot Nothing Then
Dim collection = gridControlViewInfo.LeftButtons.Concat(gridControlViewInfo.RightButtons)
Dim button As EditorButtonObjectInfoArgs = collection.ToList().Find(Function(p) p.Bounds.Contains(mousePosition))
If button IsNot Nothing Then
button.State = state
End If
Return button
Else
Return Nothing
End If
End Function
Private Sub HotTrackFilterPanelButtons(ByVal mousePosition As Point)
If gridControlViewInfo IsNot Nothing Then
Dim collection = gridControlViewInfo.LeftButtons.Concat(gridControlViewInfo.RightButtons)
Dim button As EditorButtonObjectInfoArgs = collection.ToList().Find(Function(p) p.Bounds.Contains(mousePosition))
If button IsNot Nothing Then
If button.State = ObjectState.Normal Then
button.State = ObjectState.Hot
gridControlView.InvalidateFilterPanel()
End If
Else
collection.ToList().ForEach(Sub(p) p.State = ObjectState.Normal)
gridControlView.InvalidateFilterPanel()
End If
End If
End Sub
Protected Overrides Function CreateDefaultView() As BaseView
Return CreateView("CustomGridControlView")
End Function
Protected Overrides Sub CreateMainView()
MyBase.CreateMainView()
gridControlView = (TryCast(Views.FirstOrDefault(), CustomGridControlView))
gridControlViewInfo = TryCast(Views.FirstOrDefault().GetViewInfo(), CustomGridControlViewInfo)
End Sub
Protected Overrides Sub OnMouseDown(ByVal ev As MouseEventArgs)
MyBase.OnMouseDown(ev)
Dim button As EditorButtonObjectInfoArgs = CheckMousePositionAndSetState(ev.Location, ObjectState.Pressed)
If button IsNot Nothing Then
gridControlView.InvalidateFilterPanel()
End If
End Sub
Protected Overrides Sub OnMouseMove(ByVal ev As MouseEventArgs)
MyBase.OnMouseMove(ev)
HotTrackFilterPanelButtons(ev.Location)
End Sub
Protected Overrides Sub OnMouseUp(ByVal ev As MouseEventArgs)
MyBase.OnMouseUp(ev)
Dim button As EditorButtonObjectInfoArgs = CheckMousePositionAndSetState(ev.Location, ObjectState.Normal)
If button IsNot Nothing Then
button.Button.PerformClick()
End If
End Sub
Protected Overrides Sub RegisterAvailableViewsCore(ByVal collection As InfoCollection)
MyBase.RegisterAvailableViewsCore(collection)
collection.Add(New CustomGridControlViewInfoRegistrator())
End Sub
End Class
End Namespace