Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2513
  • Last Modified:

How do I add a combobox to a VB.net PropertyGrid

I have a PropertyGrid on a simple VB.net Form.

The following class seems to work in the property grid without problem.  I would like to add a property that would add a combobox to the property grid to allow users to select an item from _property3.  

What attributes do I need to specify to use a stock combo box?

Public Class CurrentSimulationProperties

    Private _property1 As Long = -1                        
    Private _property2 As String = "Property 2"
    Private _property3 As List(Of String)
    <Description("Property 1"), _
     Category( "My Properties") > _
    Public Property Property1 As Long
            Return _property1
        End Get
        Set(ByVal value As Long)
            _property1 = value
        End Set
    End Property

    <Description("Property 2"), _
     Category( "My Properties")> _
    Public Property Property2 As String
            Return _property2
        End Get
        Set(ByVal value As string)
            _property2 = value
        End Set
    End Property

End Class
3 Solutions
Miguel OzSoftware EngineerCommented:
You need the Editor type. Quoting from link:
"In order to get the custom ComboBox to display in the PropertyGrid, you have to tell the PropertyGrid to display the data in the control. This is accomplished by adding another attribute, Editor, to the top of your property. You will have to do this for each property that you wish to show in a ComboBox.

 Collapse Copy Code[Editor( typeof( EnumGridComboBox ), typeof( UITypeEditor ) )]
[EnumList( typeof(SupplyStore.SupplyParts))]
[Category( "&" ), Description( "&" ), DisplayName( "&" )]
public SupplyStore.SupplyParts SupplyParts
    get { return _supplyPartsEnum; }
    set { _supplyPartsEnum = value; }

Wayne Taylor (webtubbs)Commented:
Generally, the editor you would use for a List(Of T) object is a StringCollectionEditor (the same as the one used by the ListBox.Items property), which allows the user to add a list of strings to the property....

    <Description("Property 3"), _
     Category("My Properties"), _
     Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", _
        "System.Drawing.Design.UITypeEditor, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")> _
    Public Property Property3() As List(Of String)
            Return _property3
        End Get
        Set(ByVal value As List(Of String))
            _property3 = value
        End Set
    End Property

Miguel OzSoftware EngineerCommented:
Glad you agree with me Wayne
Éric MoreauSenior .Net ConsultantCommented:
MDKIMZEYAuthor Commented:
Most helpful.  Thanks much!

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now