Hello Tark,
A possible way to do what you want as follows:
1. Create a class tha would hold the data items that you want to store for
each item
(for example:
public class itemclass
Public name As String
Public id As Integer
end class
An instanace of this class would contain the name that would appear for
each item and the id for that item. You could add any more data that you
need as properties for that class)
2. Create a constructor for that class that would take the values for a new
instance and set the properties correctly
(for example:
pubic sub new(byval inname as string, byval inid as integer)
name = iname
id = inid
end sub
3. Override the tostring method in that class to return the text you want
to appear for the listbox or combobox items (listbox and combobox call
tostring to show the items.
(for example:
public overrides function tostring() as string
return name
end function
4.
Add items to the list box and combobox using the .items.add method passing
them objects of the the class previously definded
(for example:
ComboBox1.Items.Add(New itemclass("First Item",1))
ComboBox1.Items.Add(New itemclass("Second Item",2))
Now the listbox and combo box should appear correctly and each item has its
id (or dataitem) saved inside it.
5. To retrieve the selecteditem and the dataitem (id) inside it, you could
use the following:
Dim selitem As itemclass = CType(ComboBox1.SelectedItem, itemclass)
message.show(selitem.id)
Hope this walkthrough helps you. Note that now you could save more than one
peice of information as you could define the itemclass class as you like.
Regards
Mohamed El Ashmawy
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC
WARNING: Microsoft provides this code "as is" without warranty of any kind,
either express or implied, including but not limited to the implied
warranties of merchantability and/or fitness for a particular purpose.