Imports System.ComponentModel
'Imports System.ComponentModel.Design
Imports System.Drawing.Design
'Imports System.Windows.Forms
Imports System.Windows.Forms.Design

Public Class ClassStaticListEditor
    Inherits UITypeEditor

    Public Overrides Function GetEditStyle(context As ITypeDescriptorContext) As UITypeEditorEditStyle
        Return UITypeEditorEditStyle.Modal
    End Function

    Public Overrides Function EditValue(context As ITypeDescriptorContext, provider As IServiceProvider, value As Object) As Object
        Dim svc As IWindowsFormsEditorService = TryCast(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)
        Dim SLString As String = DirectCast(value, StaticListValue).Value

        If svc IsNot Nothing AndAlso SLString IsNot Nothing Then
            Using Form As New frmStaticListEditor()
                SLString = SLString.Replace(";", vbNewLine) ' Semikolon zu vbNewLine
                Form.Value = SLString
                If svc.ShowDialog(Form) = DialogResult.OK Then
                    Dim str As String = Form.Value.Replace(vbNewLine, ";") ' vbNewLine zu Semikolon
                    Dim sl As New StaticListValue(str)
                    value = sl
                End If
            End Using
        End If

        Return value
    End Function
End Class

<Editor(GetType(ClassStaticListEditor), GetType(UITypeEditor))> _
<TypeConverter(GetType(StaticListTypeConverter))> _
Public Class StaticListValue
    Private _value As String

    Public Sub New(value As String)
        Me._value = value
    End Sub

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

Public Class StaticListTypeConverter
    Inherits TypeConverter

    ' Diese Funktion gibt den String zurück, der im PropertyGrid für den Benutzer sichtbar ist, kann ruhig etwas hübscher sein als foo;bar;baz
    Public Overrides Function ConvertTo(context As ITypeDescriptorContext, culture As Globalization.CultureInfo, value As Object, destinationType As Type) As Object
        Dim staticlistvalue As StaticListValue = DirectCast(value, StaticListValue)
        Dim stringvalue = staticlistvalue.Value
        Return stringvalue.Replace(";", ", ")
    End Function
End Class
