Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Custom control with ComboBox

  1. #1

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Resolved [RESOLVED] [2005] Custom control with ComboBox

    I am making a custom control that implements multiple controls, one of them being a ComboBox.

    I have the following code to edit the ComboBox's Items property.

    vb.net Code:
    1. Dim _items as Object()
    2. <Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor)), MergableProperty(False), Category("CatData"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Localizable(True), Description("ComboBoxItemsDescr")> _
    3.     Property Items() As System.Windows.Forms.ComboBox.ObjectCollection
    4.         Get
    5.             Return cmb.Items
    6.         End Get
    7.         Set(ByVal value As System.Windows.Forms.ComboBox.ObjectCollection)
    8.             value.CopyTo(_items, 0)
    9.             cmb.Items.Clear()
    10.             cmb.Items.AddRange(_items)
    11.         End Set
    12.     End Property

    That code does work, but it seems to me there may be a better way to do this. Any ideas?
    Prefix has no suffix, but suffix has a prefix.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Custom control with ComboBox

    Just create a pass-through for the ComboBox's own Items property:
    vb.net Code:
    1. Public ReadOnly Property Items() As System.Windows.Forms.ComboBox.ObjectCollection
    2.     Get
    3.         Return Me.cmb.Items
    4.     End Get
    5. End Property
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: [2005] Custom control with ComboBox

    I knew I was trying to hard. Thanks.
    Prefix has no suffix, but suffix has a prefix.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width