473,569 Members | 2,617 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 6853
Hello,

"Merlin" <iM*****@hotmai l.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.It ems.Add(p)

MessageBox.Show (DirectCast(Me. ComboBox1.Items .Item(0), Person).ToStrin g())
..
..
..
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.ToStri ng() & ")"
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.Selecte dValue
--------------------------------------

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

Watch out for the *Checked*ListBo x, 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*********@hot mail.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
8483
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
6357
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 want to do this as the selections are being made not after-the-fact after all selections are made. Thanks! Sally
1
2280
by: Mark | last post by:
How can I use the selections in a multi-select listbox as criteria in a query? Thanks! Mark
2
7959
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 combo box I am not sure after clearing how to get it back to show the first item. Regards Peter Function ClearList(lst As ListBox) As Boolean...
3
2182
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 buttons act as ‘up' and ‘down' buttons. The listbox contains some items that need to be sorted "BY THE USER" (That's why I needed the 2 command...
1
3290
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 listbox holds are Request_ID and MoveNumber. 1 text box called Date which is populated with the default value of =Date( ).
1
4812
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 Access, which isn't very helpful as it doesn't let me debug or pinpoint what's going wrong. I -think- it's at this line For Each VarItem in...
5
4074
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 and listbox are unbound. The listbox rowsource is a value list. The list box has about sixty items in it. Each item in the list box corresponds to...
5
1846
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 jumps to the error area (see code). I am at my wits end with this one. Any ideas? Form Code If Me!lstBoard.ItemsSelected.Count > 0 Then If...
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7677
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2115
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 we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.