-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclsComboBoxArray.vb
81 lines (65 loc) · 2.76 KB
/
clsComboBoxArray.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
Option Strict On
''' <summary>
''' Use this class to dynamically create combobox controls on a form and refer to them using array notation
''' Concept from http://visualbasic.about.com/od/usingvbnet/l/bldykctrlarraya.htm
''' </summary>
''' <remarks></remarks>
Public Class clsComboBoxArray
Inherits CollectionBase
Private ReadOnly HostForm As Form
Private mControlName As String
Public Property ControlName() As String
Get
Return mControlName
End Get
Set
If String.IsNullOrEmpty(Value) Then Value = ""
mControlName = Value
End Set
End Property
Public Event SelectedIndexChanged(eventSender As Object, eventArgs As EventArgs)
Public Function AddNewComboBox() As ComboBox
' Create a new instance of the ComboBox class.
Dim objComboBox As New ComboBox
AddHandler objComboBox.SelectedIndexChanged, AddressOf SelectedIndexChangedHandler
' Add the ComboBox to the collection's internal list.
Me.List.Add(objComboBox)
' Add the ComboBox to the HostForm form's Controls collection
HostForm.Controls.Add(objComboBox)
' Set intial properties for the ComboBox object.
objComboBox.BackColor = SystemColors.Window
objComboBox.Cursor = Cursors.Default
objComboBox.DropDownStyle = ComboBoxStyle.DropDownList
objComboBox.Font = New Font("Arial", 8.0!, FontStyle.Regular, GraphicsUnit.Point, 0)
objComboBox.ForeColor = SystemColors.WindowText
objComboBox.Location = New Point(152, 64)
objComboBox.Name = Me.ControlName + Count.ToString()
objComboBox.Size = New Size(81, 22)
objComboBox.Sorted = True
objComboBox.Tag = Count
Return objComboBox
End Function
Public Sub New(host As Form, Name As String)
HostForm = host
If String.IsNullOrEmpty(Name) Then Name = "ComboBox"
Me.ControlName = Name
Me.AddNewComboBox()
End Sub
Default Public ReadOnly Property Item(Index As Integer) As ComboBox
Get
Return CType(Me.List.Item(Index), ComboBox)
End Get
End Property
Public Sub Remove()
' Check to be sure there is a Label to remove.
If Me.Count > 0 Then
' Remove the last ComboBox added to the array from HostForm
' Note the use of the default property in accessing the array.
HostForm.Controls.Remove(Me(Me.Count - 1))
Me.List.RemoveAt(Me.Count - 1)
End If
End Sub
Private Sub SelectedIndexChangedHandler(eventSender As Object, eventArgs As EventArgs)
RaiseEvent SelectedIndexChanged(eventSender, eventArgs)
End Sub
End Class