0

I have a textbox usercontrol with a property of type validation which derives from one of my classes. In the designer the property gets displayed as a collection, however the items that I add to that collection doesn't get saved. Here is the complete code.

Public Class validationList
    Private _key As validationTypes
    Private _value As String

    Sub New()
      _key = 0
      _value = ""
    End Sub

    Public Sub New(ByVal k As validationTypes, ByVal v As String)
      _key = k
      _value = v
    End Sub

    Public Enum validationTypes
        man = 0
        num = 1
    End Enum

    Public Property Key As validationTypes
        Get
            Return _key
        End Get
        Set(ByVal value As validationTypes)
            _key = value
        End Set
    End Property

    Public Property value As String
        Get
            Return _value
        End Get
        Set(ByVal value As String)
            _value = value
        End Set
    End Property
End Class

And this is the property that gets exposed via the usercontrol

Private _validation As List(Of validationList)

    Public Property validation As List(Of validationList)
        Get
            Return _validation
        End Get
        Set(ByVal value As List(Of validationList))
            _validation = value
        End Set
    End Property
codeGEN
  • 686
  • 2
  • 18
  • 45
  • you are missing a whole bunch of attributes as [explained here](http://stackoverflow.com/a/24309995/1070452); also `_validation` is not handled quite right. there needs to be an instance of it (NEW), and a collection class would be more appropriate than a naked `List`. The only thing "wrong" in the prev answer is that FooBar should have different properties (like you have above) and it too uses a naked List. See also http://stackoverflow.com/a/24347944/1070452 for a collection class of Type. – Ňɏssa Pøngjǣrdenlarp Jun 22 '14 at 15:04
  • I updated the question with the missing constructors. But still it is not working. – codeGEN Jun 22 '14 at 15:12
  • No. what you are missing are ALL the <...> decorations (called Attributes) which control DesignerSerialization (ie the IDE saving collection values). And by missing a NEW I meant `_validation` is never instanced, so the IDE has no where to save your items. That previous answer is actual working code with RowFilter changed to FooBar. The second link mentioned (you may need to refresh) shows how to expose a Collection. It also wont Serialize (save) without a TypeConverter which handles a `InstanceDescriptor` for `validationList`. You are on the right path, but missing the details. – Ňɏssa Pøngjǣrdenlarp Jun 22 '14 at 15:21

0 Answers0