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?
Printable View
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?
SelectedValue(), I think.
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?
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.
ok, i quite follow you now. hmmm.... after making my class, how can i make it part of my combo box?
Like this:
VB Code:
For Each dr In ds.Tables("Products").Rows lItem = New NameOfYourClass() lItem.DisplayText = CInt(dr.Item("Something")) lItem.ItemData = dr.Item("SomethingElse").ToString ListBox1.Items.Add(lItem) Next
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 ????
Show your class.
VB Code:
Public Class clsItem Dim ItemText As String Dim ItemID As String Public Property DisplayText() As String Get DisplayText = ItemText End Get Set(ByVal Value As String) ItemText = Value End Set End Property Public Property ItemData() As String Get ItemData = ItemID End Get Set(ByVal Value As String) ItemID = Value End Set End Property End Class
Override String():
VB Code:
Public Class clsItem Dim ItemText As String Dim ItemID As String Public Property DisplayText() As String Get DisplayText = ItemText End Get Set(ByVal Value As String) ItemText = Value End Set End Property Public Property ItemData() As String Get ItemData = ItemID End Get Set(ByVal Value As String) ItemID = Value End Set End Property Public Overrides Function ToString() As String Return ItemText End Function End Class
thanks a lot man!!! It works great. cheers!!!!:)
Yes... cheers, jolly good and crumpets. Now add [resolved] to the thread title. :afrog: