Results 1 to 12 of 12

Thread: Itemdata equivalent in VB.NET [Resolved]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285

    Wink Itemdata equivalent in VB.NET [Resolved]

    hello everyone, i think this is fairly simple for you guys hmmm... what is the equivalent for the ItemData property of combo & list boxes in VB.NET?
    Last edited by guyjasper; Aug 24th, 2004 at 04:38 AM.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    SelectedValue(), I think.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285
    you think so? so does the SelectedValue() runs in parallel with the Items property? can i assign individual value in the SelectedValue() property for each items in my combo or listbox?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Ah, I see what you mean.

    Create a class which has two properties: "DisplayText" and "itemdata". Assign the values you want, and add the objects to your combobox/listbox.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285
    ok, i quite follow you now. hmmm.... after making my class, how can i make it part of my combo box?

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Like this:

    VB Code:
    1. For Each dr In ds.Tables("Products").Rows
    2.             lItem = New NameOfYourClass()
    3.             lItem.DisplayText = CInt(dr.Item("Something"))
    4.             lItem.ItemData = dr.Item("SomethingElse").ToString
    5.             ListBox1.Items.Add(lItem)
    6.         Next

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285
    i have a porblem.... the items were added fine but the text displayed in the combo box is not the value assigned to myClass.DisplayText object. The text displayed is something like this
    project_name.instance_of_my_class ????

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Show your class.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285
    VB Code:
    1. Public Class clsItem
    2.     Dim ItemText As String
    3.     Dim ItemID As String
    4.  
    5.     Public Property DisplayText() As String
    6.         Get
    7.             DisplayText = ItemText
    8.         End Get
    9.         Set(ByVal Value As String)
    10.             ItemText = Value
    11.         End Set
    12.     End Property
    13.  
    14.     Public Property ItemData() As String
    15.         Get
    16.             ItemData = ItemID
    17.         End Get
    18.         Set(ByVal Value As String)
    19.             ItemID = Value
    20.         End Set
    21.     End Property
    22. End Class

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Override String():


    VB Code:
    1. Public Class clsItem
    2.     Dim ItemText As String
    3.     Dim ItemID As String
    4.  
    5.     Public Property DisplayText() As String
    6.         Get
    7.             DisplayText = ItemText
    8.         End Get
    9.         Set(ByVal Value As String)
    10.             ItemText = Value
    11.         End Set
    12.     End Property
    13.  
    14.     Public Property ItemData() As String
    15.         Get
    16.             ItemData = ItemID
    17.         End Get
    18.         Set(ByVal Value As String)
    19.             ItemID = Value
    20.         End Set
    21.     End Property
    22.  
    23.     Public Overrides Function ToString() As String
    24.         Return ItemText
    25.     End Function
    26.  
    27. End Class

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285
    thanks a lot man!!! It works great. cheers!!!!

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Yes... cheers, jolly good and crumpets. Now add [resolved] to the thread title.

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