0

I am using a class library in Visual Basic 2010 Express Edition to make a custom textbox control. How do I add a dropdown property for the textbox?

I need a dynamic dropdown menu not like when you using

Enum MaxValue
   item1 = 0
End Enum

because I have to get the items from the database.

I tried adding a browsable option but nothing happened:

<Browsable(True)>
Property Max_Value() As String

     Get
        Return MaxValue
     End Get

     Set(value As String
        MaxValue = value
     End Set
End Property
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eng. Chmai
  • 11
  • 3

1 Answers1

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

    Public Class TestTextBox
            Inherits TextBox

            <Browsable(True)>
            <Editor(GetType(Editor), GetType(UITypeEditor))>
            <DefaultValue("Hello")>
            Public Property MyProperty As String

            Private Class Editor
                    Inherits UITypeEditor

                    Private mSvc As IWindowsFormsEditorService

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

                    Public Overrides Function EditValue(context As ITypeDescriptorContext, provider As IServiceProvider, value As Object) As Object
                            mSvc = CType(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)

                            Dim lb As New ListBox()
                            For Each value In {"Hello", "Whats", "Happening"}
                                    lb.Items.Add(value)
                            Next

                            If value IsNot Nothing Then
                                    lb.SelectedItem = value
                            End If

                            mSvc.DropDownControl(lb)

                            value = DirectCast(lb.SelectedItem, String)

                            Return value
                    End Function

            End Class

    End Class
FloatingKiwi
  • 4,408
  • 1
  • 17
  • 41