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

Public Class StaticListEditor
    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 oService As IWindowsFormsEditorService = TryCast(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)
        Dim oStaticListString As String = DirectCast(value, StaticList).Value

        If oService IsNot Nothing AndAlso oStaticListString IsNot Nothing Then
            Using oForm As New frmStaticListEditor()
                oStaticListString = oStaticListString.Replace(";", vbNewLine) ' Semikolon zu vbNewLine
                oForm.Value = oStaticListString
                If oService.ShowDialog(oForm) = DialogResult.OK Then
                    Dim oString As String = oForm.Value.Replace(vbNewLine, ";") ' vbNewLine zu Semikolon
                    Dim oStaticList As New StaticList(oString)
                    value = oStaticList
                End If
            End Using
        End If

        Return value
    End Function
End Class

<Editor(GetType(StaticListEditor), GetType(UITypeEditor))>
<TypeConverter(GetType(StaticListTypeConverter))>
Public Class StaticList

    Public Sub New()
        _Value = String.Empty
    End Sub

    Public Sub New(Value As String)
        _Value = Value
    End Sub

    Public Property Value As String
End Class

Public Class StaticListTypeConverter
    Inherits TypeConverter


    Public Overrides Function ToString() As String
        Return MyBase.ToString()
    End Function

    ' 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 oStaticListString = String.Empty

        If TypeOf value Is StaticList Then
            Dim oStaticList As StaticList = DirectCast(value, StaticList)
            oStaticListString = oStaticList.Value
        ElseIf TypeOf value Is String Then
            oStaticListString = value
        Else
            MsgBox("Error in Converting StaticList value")
        End If

        Return oStaticListString.Replace(";", ", ")
    End Function
End Class
