Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

ListBox problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Guy Dillen - 06 Dec 2004 21:18 GMT
I need to fill a ListBox with data, NOT related to a database. I would like
presenting the description in the ListBox, and an ID needs to be available
when an item is selected in the ListBox.

How can i do this (using an Array? using a second invisible ListBox?) ???

Thanks for any help?

Guy
Herfried K. Wagner [MVP] - 06 Dec 2004 21:27 GMT
"Guy Dillen" <guy_dillen@nospam.hotmail.com> schrieb:
>I need to fill a ListBox with data, NOT related to a database. I would like
>presenting the description in the ListBox, and an ID needs to be available
>when an item is selected in the ListBox.
>
> How can i do this (using an Array? using a second invisible ListBox?) ???

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

' Test.
MessageBox.Show(DirectCast(Me.ComboBox1.Items.Item(0), Person).ToString())
.
.
.
Public Class Person
   Private m_Name As String
   Private m_Age As Integer

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

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

   Public Overrides Function ToString() As String
       Return Me.Name & " (" & Me.Age.ToString() & ")"
   End Function
End Class
///

Alternatively, you can use a bound combobox:

\\\
With Me.ListBox1

   ' This can be an 'ArrayList' or array too, for example!
   .DataSource = Database.FindPeople(...)
   .DisplayMember = "Name"
   .ValueMember = "Age"
End With
///

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.