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 0
/
TreeListBandedCustomizationForm.vb
151 lines (135 loc) · 5.09 KB
/
TreeListBandedCustomizationForm.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
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports DevExpress.XtraGrid.Views.BandedGrid.Customization
Imports DevExpress.XtraGrid.Views.BandedGrid
Imports DevExpress.XtraTreeList
Imports DevExpress.XtraTreeList.Nodes
Imports DevExpress.XtraTreeList.Columns
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraGrid.Columns
Imports System.Collections
Imports DevExpress.Utils
Imports DevExpress.Utils.Drawing
Namespace TreeListCustomization
Friend Class TreeListBandedCustomizationForm
Inherits BandedCustomizationForm
Private bandsColumnTreeList_ As TreeList
Private ReadOnly Property BandsColumnTreeList() As TreeList
Get
Return bandsColumnTreeList_
End Get
End Property
Private UnvisibleList As New ArrayList()
Private customCellPainter As New SkinHeaderObjectPainter(DevExpress.LookAndFeel.UserLookAndFeel.Default.ActiveLookAndFeel)
Public Sub New(ByVal gridView As BandedGridView)
MyBase.New(gridView)
End Sub
Protected Overrides Sub CreateListBox()
bandsColumnTreeList_ = New TreeListForBands(Me)
Dim newColumn As TreeListColumn = bandsColumnTreeList_.Columns.Add()
newColumn.FieldName = "Content"
newColumn.VisibleIndex = 0
newColumn.OptionsColumn.AllowEdit = False
newColumn.OptionsColumn.ReadOnly = True
bandsColumnTreeList_.OptionsView.ShowColumns = False
bandsColumnTreeList_.OptionsView.ShowIndicator = False
FillBandsColumnTreeList()
bandsColumnTreeList_.Dock = DockStyle.Fill
Controls.Add(bandsColumnTreeList_)
AddHandler BandsColumnTreeList.CustomDrawNodeCell, AddressOf BandsColumnTreeList_CustomDrawNodeCell
End Sub
Private Sub BandsColumnTreeList_CustomDrawNodeCell(ByVal sender As Object, ByVal e As CustomDrawNodeCellEventArgs)
Dim band As GridBand = TryCast(e.Node(0), GridBand)
If band IsNot Nothing AndAlso (Not band.Visible) Then
DrawNodeElementAsColumn(e)
End If
Dim gridColumn As BandedGridColumn = TryCast(e.Node(0), BandedGridColumn)
If gridColumn IsNot Nothing AndAlso ((Not gridColumn.Visible) OrElse gridColumn.OwnerBand Is Nothing) Then
DrawNodeElementAsColumn(e)
End If
End Sub
Private Sub DrawNodeElementAsColumn(ByVal e As CustomDrawNodeCellEventArgs)
Dim infoArgs As New HeaderObjectInfoArgs()
infoArgs.Bounds = Rectangle.Inflate(e.Bounds, -1, 0)
infoArgs.Cache = e.Cache
infoArgs.Caption = e.CellText
infoArgs.CaptionRect = e.Bounds
infoArgs.TopLeft = New Point(infoArgs.CaptionRect.X, infoArgs.CaptionRect.Y + 3)
customCellPainter.DrawObject(infoArgs)
e.Handled = True
End Sub
Public Overrides Sub UpdateListBox()
End Sub
Protected Overrides Sub SetDefaultFormSize()
End Sub
Public Overrides Sub CheckAndUpdate()
BandsColumnTreeList.Nodes.Clear()
FillBandsColumnTreeList()
End Sub
Private Sub FillUnvisibleElementsArray()
UnvisibleList.Clear()
For Each band As GridBand In View.Bands
If (Not band.Visible) AndAlso band.OptionsBand.ShowInCustomizationForm Then
UnvisibleList.Add(band)
End If
AddBandChildren(band)
Next band
For Each column As GridColumn In View.Columns
If column.CanShowInCustomizationForm Then
UnvisibleList.Add(column)
End If
Next column
End Sub
Private Sub AddBandChildren(ByVal band As GridBand)
If (Not band.HasChildren) Then
Return
End If
For Each bd As GridBand In band.Children
If (Not bd.Visible) AndAlso bd.OptionsBand.ShowInCustomizationForm Then
UnvisibleList.Add(bd)
AddBandChildren(bd)
End If
Next bd
End Sub
Private Sub FillBandsColumnTreeList()
UnvisibleList.Clear()
FillUnvisibleElementsArray()
For Each item As Object In UnvisibleList
Dim newNode As TreeListNode = Nothing
If TypeOf item Is GridBand Then
newNode = AddBandAsTreeNode(TryCast(item, GridBand))
End If
If TypeOf item Is BandedGridColumn Then
newNode = AddBandedColumnAsTreeNode(TryCast(item, BandedGridColumn))
End If
Next item
End Sub
Private Function AddBandAsTreeNode(ByVal band As GridBand) As TreeListNode
If band.ParentBand Is Nothing Then
Dim currentNode As TreeListNode = BandsColumnTreeList.FindNodeByFieldValue("Content", band)
If currentNode Is Nothing Then
currentNode = BandsColumnTreeList.AppendNode(New Object() {band}, -1)
End If
Return currentNode
Else
Dim parentNode As TreeListNode = AddBandAsTreeNode(band.ParentBand)
Return BandsColumnTreeList.AppendNode(New Object() { band }, parentNode)
End If
End Function
Private Function AddBandedColumnAsTreeNode(ByVal bandedColumn As BandedGridColumn) As TreeListNode
If bandedColumn.OwnerBand Is Nothing Then
Return BandsColumnTreeList.AppendNode(New Object() {bandedColumn}, -1)
Else
Dim parentNode As TreeListNode = BandsColumnTreeList.FindNodeByFieldValue("Content", bandedColumn.OwnerBand)
If parentNode Is Nothing Then
parentNode = AddBandAsTreeNode(bandedColumn.OwnerBand)
End If
Return BandsColumnTreeList.AppendNode(New Object() { bandedColumn }, parentNode)
End If
End Function
End Class
End Namespace