-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyInvisibleIndexes.vb
171 lines (120 loc) · 3.42 KB
/
MyInvisibleIndexes.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
Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Namespace MyComboBoxEdit
Friend Class MyInvisibleIndexes
Private comboBox As ComboBoxEdit
Private contentList As List(Of Integer)
Private itemsChange As CollectionChangeEventHandler
Private itemMeasure As MeasureItemEventHandler
Default Public Property Item(ByVal index As Integer) As Integer
Get
Return contentList(index)
End Get
Set(ByVal value As Integer)
contentList(index) = value
End Set
End Property
Public Sub New(ByVal comboBox As ComboBoxEdit)
itemsChange = Nothing
itemMeasure = Nothing
contentList = New List(Of Integer)()
Me.comboBox = comboBox
Init()
End Sub
Protected Overrides Sub Finalize()
If comboBox IsNot Nothing Then
Try
RemoveHandler comboBox.Properties.MeasureItem, itemMeasure
RemoveHandler comboBox.Properties.Items.CollectionChanged, itemsChange
Catch
End Try
End If
End Sub
Private Sub Init()
If comboBox IsNot Nothing Then
If itemsChange Is Nothing Then
itemsChange = New CollectionChangeEventHandler(AddressOf OnItemsChanged)
AddHandler comboBox.Properties.Items.CollectionChanged, itemsChange
End If
If itemMeasure Is Nothing Then
itemMeasure = New MeasureItemEventHandler(AddressOf OnMeasureItem)
AddHandler comboBox.Properties.MeasureItem, itemMeasure
End If
End If
End Sub
Private Sub OnItemsChanged(ByVal sender As Object, ByVal e As CollectionChangeEventArgs)
Dim combo As ComboBoxEdit = TryCast(sender, ComboBoxEdit)
If combo Is Nothing Then
Return
End If
Dim countItems As Integer = combo.Properties.Items.Count
If countItems = 0 Then
contentList.Clear()
Return
End If
Dim ndx As Integer = 0
Do While ndx < contentList.Count
If contentList(ndx) >= countItems Then
contentList.RemoveAt(ndx)
Continue Do
End If
ndx += 1
Loop
End Sub
Private Sub OnMeasureItem(ByVal sender As Object, ByVal e As MeasureItemEventArgs)
If contentList.Contains(e.Index) Then
e.ItemHeight = 0
e.ItemWidth = 0
End If
End Sub
Private Sub ClearPopup()
Dim control As Control = (TryCast(comboBox, DevExpress.Utils.Win.IPopupControl)).PopupWindow
If control IsNot Nothing Then
control.Parent = Nothing
control.Dispose()
End If
End Sub
Public Function Add(ByVal value As Integer) As Integer
Dim iResult As Integer = -1
If comboBox Is Nothing OrElse contentList.Contains(value) Then
Return iResult
End If
Try
ClearPopup()
contentList.Add(value)
iResult = contentList.Count - 1
Catch
End Try
Return iResult
End Function
Public Sub AddRange(ByVal indexes() As Integer)
If indexes Is Nothing Then
Return
End If
For i As Integer = 0 To indexes.Length - 1
Add(indexes(i))
Next i
End Sub
Public Sub Clear()
contentList.Clear()
End Sub
Public Function Contains(ByVal value As Integer) As Boolean
Return contentList.Contains(value)
End Function
Public Function IndexOf(ByVal value As Integer) As Integer
Return contentList.IndexOf(value)
End Function
Public ReadOnly Property Count() As Integer
Get
Return contentList.Count
End Get
End Property
Public Sub Remove(ByVal value As Integer)
contentList.Remove(value)
End Sub
End Class
End Namespace