Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox, ID's, and Selecting an Item

Status
Not open for further replies.

areric

Programmer
Jul 13, 2003
47
0
0
US
Hey everyone, Im trying to make a listbox that will list an id, subject, and content for a group of items. Id prefer for content and ID to be hidden but accessable. I.E. I can use id for passing to other functions.

That said i know this was easier in VB 6 but how do i make a listbox and then have each item have an ID. when i select the item i need to be able to pull the subject content (both strings) and id (int) from the selected item.

If anyone has any ideas its appreciated

Thanks
 
See thread796-656160

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
I think you could better use a class.

Creat a class (project | add class) Item (or another name.

then use the property's (readonly writeonly)

The best thing about the class is that you can overwrite the ToString Function so that is the thing that will be shown.

for example :

public class Item

private id as integer
private subject as string
private content as string

public sub new(id as int, subject as string, content as string)
'here you fill in the private variables
end sub

'make some properties for the things that you want (readonly, writeonly or normal)
public readonly property ID as integer
Get
Return ID
End Get
end property

Public Overrides Function ToString() As String
return subject
end function

now in the code :

dim itm as item = new item(1,"subject","content")
listbox1.items.add(itm)

now when you select an item,

dim itm as item = ListBox1.SelectedItem()
messagebox.show(itm.ID)

This is a general id on how most programmrs use classes to populate a listbox, combobox, textbox, ...

hope this helps you and that it works, because i wrote it here and not in .net.

To search or to post - that is the question.
To search first and to post later. THAT is the answer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top