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, DataReader, ID and Description

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Guy Dillen - 04 Dec 2004 09:17 GMT
I would like using a DataReader to fille a listbox with descriptions, on the
other hand i need to store somwhere an ID (to the respective Descriptions),
that i can use as a key when a listbox item has ben selected.

I know i can use a second invisible listbox that stores the ID's in it, but
are there alternatives to solve this problem (with a DataReader) more
elegant? Maybe using the Tag property?

Thanks
Guy
Herfried K. Wagner [MVP] - 04 Dec 2004 11:25 GMT
"Guy Dillen" <guy_dillen@nospam.hotmail.com> schrieb:
>I would like using a DataReader to fille a listbox with descriptions, on
>the other hand i need to store somwhere an ID (to the respective
>Descriptions), that i can use as a key when a listbox item has ben
>selected.

Take a look at the control's 'DisplayMember', 'ValueMember', and
'DataSource' properties.

Signature

Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/

Guy Dillen - 04 Dec 2004 11:56 GMT
Ok, i already did, but does DataSource/DisplayMember/ValueMember also work
with a DataReader?

Guy

> "Guy Dillen" <guy_dillen@nospam.hotmail.com> schrieb:
>>I would like using a DataReader to fille a listbox with descriptions, on
[quoted text clipped - 4 lines]
> Take a look at the control's 'DisplayMember', 'ValueMember', and
> 'DataSource' properties.
Nicola - 04 Dec 2004 13:35 GMT
I don't think it's possible, but why use DataReader ???
I implemented it filling a table, added to a DataSet through a DataAdapter:

Dim DS as DataSet
Dim N as string="TableName"
Dim SQL as string="SELECT * FROM ..."
Dim CN as New SQLConnection(ConnectionString)
Dim CMD As New SqlCommand(SQL, CN), DA As New SqlDataAdapter(CMD)
DS.Tables.Add(N) : DA.Fill(DS.Tables(N))
ListBox.ValueMember = ID
ListBox.DisplayMember = Description
ListBox.DataSource = DS.Tables(N)
ListBox.SelectedIndex = -1 : ListBox.SelectedIndex = -1

I hope this can help You
nq

> Ok, i already did, but does DataSource/DisplayMember/ValueMember also work
> with a DataReader?
[quoted text clipped - 9 lines]
> > Take a look at the control's 'DisplayMember', 'ValueMember', and
> > 'DataSource' properties.

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.