|
-
Aug 6th, 2006, 02:05 AM
#1
Thread Starter
Fanatic Member
listbox additem
i want to add items in a listbox along with its corresponding id.
my code :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim obj As class1
obj = New class1
obj.name = "xyz"
obj.id = 1
ListBox1.Items.Add(obj)
obj = New class1
obj.name = "pqr"
obj.id = 2
ListBox1.Items.Add(obj)
End Sub
Private Class class1
Public name As String
Public id As Integer
End Class
result shown on the form is :
windowsapplication1.form1+class1
windowsapplication1.form1+class1
Any suggestions.
-
Aug 6th, 2006, 02:56 AM
#2
Re: listbox additem
You cannot do that with the WinForms ListBox, only with the WebForms version. If you want a hidden value associated with each displayed value then you have to create a data source and bind it to the ListBox. If you aren't aware of how to use them already, look up the DataSource, DisplayMember, ValueMember and SelectedValue properties.
-
Aug 6th, 2006, 03:09 PM
#3
Fanatic Member
Re: listbox additem
You'd be better off using the ListView control. You could stored hidden values in each ListViewItem's Tag property.
http://msdn.microsoft.com/library/de...ClassTopic.asp
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|