Hello,
I'm new on this page and on VB.Net and want's to create an simple control. But for this I need a property with DataType is collection. In the collection I want to have an object with two properties ('Prop' and 'Value'). I have defined this property, but VB.Net doesn't save my edits in the built in CollectionEditor.
At the Control I have inserted the following code:
The definition of the CustomPropertyCollection and the object in the collection is:
The Part with the Converter I have seen in a sample for this page (outlookbartest). I don't know if I need it...
Please help me...
Vocaris
I'm new on this page and on VB.Net and want's to create an simple control. But for this I need a property with DataType is collection. In the collection I want to have an object with two properties ('Prop' and 'Value'). I have defined this property, but VB.Net doesn't save my edits in the built in CollectionEditor.
At the Control I have inserted the following code:
Code:
Public ReadOnly Property CustomProperties() As CustomPropertyCollection
Get
Return mvcolCustomPropertyCollection
End Get
End Property
The definition of the CustomPropertyCollection and the object in the collection is:
Code:
Friend Class CustomPropertyConverter
Inherits System.ComponentModel.TypeConverter
Public Overloads Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destType As Type) As Boolean
If destType Is GetType(System.ComponentModel.Design.Serialization.InstanceDescriptor) Then
Return True
End If
Return MyBase.CanConvertTo(context, destType)
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destType As Type) As Object
If destType Is GetType(System.ComponentModel.Design.Serialization.InstanceDescriptor) Then
Dim cat As CustomProperty = DirectCast(value, CustomProperty)
Dim ci As System.Reflection.ConstructorInfo = GetType(CustomProperty).GetConstructor(System.Type.EmptyTypes)
Return New System.ComponentModel.Design.Serialization.InstanceDescriptor(ci, Nothing, False)
End If
Return MyBase.ConvertTo(context, culture, value, destType)
End Function
End Class
Public Class CustomProperty
Dim mvstrProperty As String
Dim mvstrValue As String
Public Property Prop() As String
Get
Prop = mvstrProperty
End Get
Set(ByVal pvstrProp As String)
mvstrProperty = pvstrProp
End Set
End Property
Public Property Value() As String
Get
Value = mvstrValue
End Get
Set(ByVal pvstrValue As String)
mvstrValue = pvstrValue
End Set
End Property
End Class
Public Class CustomPropertyCollection
Inherits CollectionBase
'Needed to implement the strongly-typed collection
Default Public Property Item(ByVal Index As Integer) As CustomProperty
Get
Return DirectCast(List.Item(Index), CustomProperty)
End Get
Set(ByVal Value As CustomProperty)
List.Item(Index) = Value
End Set
End Property
Public Function Add(ByVal Item As CustomProperty) As Integer
Return List.Add(Item)
End Function
Public Sub Insert(ByVal index As Integer, ByVal Item As CustomProperty)
If List.Contains(Item) Then
Throw New InvalidOperationException("Already in list.")
End If
List.Insert(index, Item)
End Sub
Public Function Contains(ByVal value As CustomProperty) As Boolean
Return List.Contains(value)
End Function
'Redraw the control
Protected Overrides Sub OnClearComplete()
MyBase.OnClearComplete()
End Sub
'Redraw the control and wire up button's redrawneeded event
Protected Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal value As Object)
MyBase.OnInsertComplete(index, value)
End Sub
'Redraw the control
Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal value As Object)
MyBase.OnRemoveComplete(index, value)
End Sub
End Class
The Part with the Converter I have seen in a sample for this page (outlookbartest). I don't know if I need it...
Please help me...
Vocaris