Results 1 to 4 of 4

Thread: ComboBox - ItemData

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2003
    Location
    The Future - Skynet
    Posts
    1,157

    ComboBox - ItemData

    How do I do an ItemData for a combobox in VB.Net?
    I'll Be Back!

    T-1000

    Microsoft .Net 2005
    Microsoft Visual Basic 6
    Prefer using API

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    One way you can do it is to create your own comboitem class like so:

    VB Code:
    1. Public Class clsCboItem
    2.     Public sVal As String
    3.     Public lData As Long
    4.     Overrides Function ToString() As String
    5.         Return sVal
    6.     End Function
    7. End Class

    Then when you are adding to the combo box, you do this:

    VB Code:
    1. Dim t As New clsCboItem
    2.         t.sVal = "A"
    3.         t.lData = 56
    4.         ComboBox1.Items.Add(t)
    5.         t = Nothing
    6.         t = New clsCboItem
    7.         t.sVal = "C"
    8.         t.lData = 69
    9.         ComboBox1.Items.Add(t)
    10.  
    11.         MsgBox(ComboBox1.Items(0).ldata)

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2003
    Location
    The Future - Skynet
    Posts
    1,157
    Hi,

    I am new to this. Where do I place that code and is that the actual code that will work?

    Thank You
    I'll Be Back!

    T-1000

    Microsoft .Net 2005
    Microsoft Visual Basic 6
    Prefer using API

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Add a new class to your app via Project->Add Class and call it clsCboItem. Then place the class code in that module.

    The other code was just an example on how to use it. You can place that in a button click event.

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