Results 1 to 4 of 4

Thread: [RESOLVED] Inherit ComboBox class to add TAG property for each item

  1. #1

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Resolved [RESOLVED] Inherit ComboBox class to add TAG property for each item

    I expected to find the TAG property for each item in the ComboBox. Since, there is not, I now expect it can herited to add the property.
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Inherit ComboBox class to add TAG property for each item

    Well, no. The items are all strings, however you can add objects instead of just strings to the ComboBox, these objects can have a Tag property (or any property you would like to give it).
    Code:
    Public Class MyListItem
      Public Property Text As String
      Public Property SomeOtherValue As Integer
    End Class
    
    'somewhere else in your code
    Dim myItem As New MyListItem
    myItem.Text = "Hello"
    myItem.SomeOtherValue = 32
    ComboBox1.DisplayMember = "Text" 'Make sure the Text property is used to display the item
    ComboBox1.Items.Add(myItem)
    '....
    Dim x As Integer = DirectCast(ComboBox1.SelectedItem, MyListItem).SomeOtherValue
    Edit This assumes you're talking about the Windows Forms ComboBox.
    Last edited by Joacim Andersson; Jan 19th, 2013 at 10:58 AM.

  3. #3

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Inherit ComboBox class to add TAG property for each item

    Serves my purpose, perfectly. Thanks!
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  4. #4
    New Member
    Join Date
    Sep 2015
    Posts
    1

    Re: Inherit ComboBox class to add TAG property for each item

    Glad I found this, thanks!

    How can I select a comboboxitem programatically based on this SomeOtherValue property?

Tags for this Thread

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