File size: 4,516 Bytes
b1b3bae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Windows.Forms.Design

Namespace PropertyGridEx
    <Serializable()> _
    Public Class CustomChoices
        Inherits ArrayList

        Public Sub New(ByVal array As ArrayList, ByVal IsSorted As Boolean)
            Me.AddRange(array)
            If IsSorted Then Me.Sort()
        End Sub

        Public Sub New(ByVal array As ArrayList)
            Me.AddRange(array)
        End Sub

        Public Sub New(ByVal array() As String, ByVal IsSorted As Boolean)
            Me.AddRange(array)
            If IsSorted Then Me.Sort()
        End Sub

        Public Sub New(ByVal array() As String)
            Me.AddRange(array)
        End Sub

        Public Sub New(ByVal array() As Integer, ByVal IsSorted As Boolean)
            Me.AddRange(array)
            If IsSorted Then Me.Sort()
        End Sub

        Public Sub New(ByVal array() As Integer)
            Me.AddRange(array)
        End Sub

        Public Sub New(ByVal array() As Double, ByVal IsSorted As Boolean)
            Me.AddRange(array)
            If IsSorted Then Me.Sort()
        End Sub

        Public Sub New(ByVal array() As Double)
            Me.AddRange(array)
        End Sub

        Public Sub New(ByVal array() As Object, ByVal IsSorted As Boolean)
            Me.AddRange(array)
            If IsSorted Then Me.Sort()
        End Sub

        Public Sub New(ByVal array() As Object)
            Me.AddRange(array)
        End Sub

        Public ReadOnly Property Items() As ArrayList
            Get
                Return Me
            End Get
        End Property

        Public Class CustomChoicesTypeConverter
            Inherits TypeConverter
            Private oChoices As CustomChoicesAttributeList = Nothing
            Public Overrides Function GetStandardValuesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
                Dim Choices As CustomChoicesAttributeList = context.PropertyDescriptor.Attributes(GetType(CustomChoicesAttributeList))
                If Not oChoices Is Nothing Then Return True
                If Not Choices Is Nothing Then
                    oChoices = Choices
                    GetStandardValuesSupported = True
                Else
                    GetStandardValuesSupported = False
                End If
            End Function
            Public Overrides Function GetStandardValuesExclusive(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
                Dim Choices As CustomChoicesAttributeList = context.PropertyDescriptor.Attributes(GetType(CustomChoicesAttributeList))
                If Not oChoices Is Nothing Then Return True
                If Not Choices Is Nothing Then
                    oChoices = Choices
                    GetStandardValuesExclusive = True
                Else
                    GetStandardValuesExclusive = False
                End If
            End Function
            Public Overrides Function GetStandardValues(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.ComponentModel.TypeConverter.StandardValuesCollection
                Dim Choices As CustomChoicesAttributeList = context.PropertyDescriptor.Attributes(GetType(CustomChoicesAttributeList))
                If Not oChoices Is Nothing Then
                    Return oChoices.Values
                End If
                Return MyBase.GetStandardValues(context)
            End Function
        End Class

        Public Class CustomChoicesAttributeList
            Inherits Attribute
            Private oList As New ArrayList

            Public ReadOnly Property Item() As ArrayList
                Get
                    Return Me.oList
                End Get
            End Property

            Public ReadOnly Property Values() As TypeConverter.StandardValuesCollection
                Get
                    Return New TypeConverter.StandardValuesCollection(Me.oList)
                End Get
            End Property

            Public Sub New(ByVal List() As String)
                MyBase.New()
                oList.AddRange(List)
            End Sub

            Public Sub New(ByVal List As ArrayList)
                MyBase.New()
                oList.AddRange(List)
            End Sub

            Public Sub New(ByVal List As ListBox.ObjectCollection)
                MyBase.New()
                oList.AddRange(List)
            End Sub
        End Class
    End Class
End Namespace