473,508 Members | 2,130 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Listbox Itemdata

Been using VS NET for a while now but never really used the Standard ListBox
control until now and whoops! where's the ItemData method gone - damn!,
can't Microsoft leave things alone.

Anyway did a quick read up and found that Listbox is not limited to strings
anymore and each item can contain an object bla bla bla...Z Z z z z...

Can someone please put me out of my misery and just quickly show me how to
add a string item and a value like in the VB6 version. Been looking for
examples but can't actually find anything that actually gets to the point.

All I want to do is add 20 text items with an associated Long number(key).
and when I select an item, to be able to also access the (key).

Many Many thanks.

Merlin


Nov 19 '05 #1
2 6849
Hello,

"Merlin" <iM*****@hotmail.com> schrieb:
Been using VS NET for a while now but never really used
the Standard ListBox control until now and whoops! where's the
ItemData method gone - damn!, can't Microsoft leave things alone.


\\\
Dim p As Person = New Person()
p.Name = "Pink Panther"
p.Age = 22

Me.ComboBox1.Items.Add(p)

MessageBox.Show(DirectCast(Me.ComboBox1.Items.Item (0), Person).ToString())
..
..
..
Public Class Person
Private m_strName As String
Private m_ingAge As Integer

Public Property Name() As String
Get
Return m_strName
End Get
Set(ByVal Value As String)
m_strName = Value
End Set
End Property

Public Property Age() As Integer
Get
Return m_intAge
End Get
Set(ByVal Value As Integer)
m_intAge = Value
End Set
End Property

Public Overrides Function ToString() As String
Return m_strName & " (" & m_intAge.ToString() & ")"
End Function
End Class
///

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #2
Doz
Merlin my friend, I know just how you feel.

The fastest way is to use the databinding stuff (*Yuk*):
------------------
'Get yer data:
sSQL = "SELECT FruitID, FruitName FROM Fruits"
ds = GetDataset(sSQL)

With ListBox
.DataSource = ds.Tables(0) 'only table in ds
.DisplayMember = "FruitName"
.ValueMember = "FruitID"
End with

ds.dispose()
------------------
Yes, that will actually populate it, keys and all!

If you try to be really economical and do it with a
datareader, well, sorry you can't bind the thing.
(disappointing, I know).

Anyway to get your key back out from the selected:
----------------------------------
Dim nSelectedKey as integer

nSelectedKey = ListBox.SelectedValue
--------------------------------------

Remember "SELECTED" is the point here. The Item must have
the highlight (selection).

Watch out for the *Checked*ListBox, that will really make
you angry!

Good luck

Doz
___.-~@~-.___
Dorian Hill.
Microsoft Certified Solution Developer
Momentech Software Services
PO Box 348, Caulfield East, VIC 3145, Australia
E-Mail: do*********@hotmail.com

-----Original Message-----
Been using VS NET for a while now but never really used the Standard ListBoxcontrol until now and whoops! where's the ItemData method gone - damn!,can't Microsoft leave things alone.

Anyway did a quick read up and found that Listbox is not limited to stringsanymore and each item can contain an object bla bla bla...Z Z z z z...
Can someone please put me out of my misery and just quickly show me how toadd a string item and a value like in the VB6 version. Been looking forexamples but can't actually find anything that actually gets to the point.
All I want to do is add 20 text items with an associated Long number(key).and when I select an item, to be able to also access the (key).
Many Many thanks.

Merlin


.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8480
by: John Guarnieri | last post by:
Hi All, I need some code to drag items in a list box either up or down along with not just the text but with the itemdata too. Can anyone hook me up? TIA John
2
6350
by: Sally | last post by:
I have a simple multiselect listbox with a rowsorce of MemberID, MemberName, SendLetter. SendLetter is a Yes/No field. What is the code to set SendLetter to Yes when the user selects MemberName? I...
1
2275
by: Mark | last post by:
How can I use the selections in a multi-select listbox as criteria in a query? Thanks! Mark
2
7955
by: Peter Bailey | last post by:
I have a function courtesy of the newsgroup that clears the list box. I would like to now set the listbox back to its initial state where you can see the first item in the list. The same goes for a...
3
2178
by: BVH | last post by:
Hi, I'm currently having a problem with a vb6 project I once wrote that needs to be converted to vb.NET. The problem is as follows : On a form I have a listbox and two commandbuttons. The 2...
1
3281
by: JNariss | last post by:
Hello, I have created a form called frmS2P with the following: 1 listbox called List11 which holds the contents of a query created off my table called tblRequestActions. The fields which the...
1
4808
by: Selesti | last post by:
I've created a form dialog box with several checkboxes to determine which offices to include in a sales report. However, I'm getting an "Object doesn't support this property or method" error from MS...
5
4071
by: Matthew Wells | last post by:
I have a listbox set to simple multi select. For this example, users only select one item at a time. I have command buttons on the form for First, Previous, Next, Last, New (record). The form...
5
1839
by: rjchristensen | last post by:
Hello all, I am trying to use the selections from a multi-select listbox to modify selection criteria. When I try to reference either the listbox.column or listbox.itemdata values, the system...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.