473,395 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

vb.net 2005 - how to populate a listbox

Please direct me to a source which will explain how to populate a listbox
with retrievable values.

For example, I would like to display the customer name from the customer
table, but store the Customer ID which is available when an customer is
selected from the listbox.

Thanks
Apr 24 '06 #1
5 9083
Hi bill,

If you create a DataTable from your customer table with ID and Name in it
you can set it as the DataSource of your list box, then set DisplayMember
and ValueMember to the name and ID respectively.

You then call the ListBox.SelectedValue in the postback.

Steve.
"bill" <be****@datamti.com> wrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
Please direct me to a source which will explain how to populate a listbox
with retrievable values.

For example, I would like to display the customer name from the customer
table, but store the Customer ID which is available when an customer is
selected from the listbox.

Thanks

Apr 24 '06 #2
Bill,

Dim dtIDA As New DataTable
dtIDA.Columns.Add("IDA", GetType(System.String))
dtIDA.Columns.Add("Description")
dtIDA.LoadDataRow(New Object() {"FQ", "Faqs"}, True)
dtIDA.LoadDataRow(New Object() {"DX", "DirextX"}, True)
dtIDA.LoadDataRow(New Object() {"LK", "Links"}, True)
dtIDA.DefaultView.Sort = "Description"
lstTitles.DataSource = dtIDA.DefaultView
lstTitles.DisplayMember = "Description"
lstTitles.ValueMember = "IDA"

Do you mean something as above

I hope this helps,

Cor
"bill" <be****@datamti.com> schreef in bericht
news:u7**************@TK2MSFTNGP03.phx.gbl...
Please direct me to a source which will explain how to populate a listbox
with retrievable values.

For example, I would like to display the customer name from the customer
table, but store the Customer ID which is available when an customer is
selected from the listbox.

Thanks

Apr 24 '06 #3
Thanks!

"Steve Lloyd" <st**********@livenowpaylater.this.co.uk> wrote in message
news:uf*************@TK2MSFTNGP02.phx.gbl...
Hi bill,

If you create a DataTable from your customer table with ID and Name in it
you can set it as the DataSource of your list box, then set DisplayMember
and ValueMember to the name and ID respectively.

You then call the ListBox.SelectedValue in the postback.

Steve.
"bill" <be****@datamti.com> wrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
Please direct me to a source which will explain how to populate a listbox
with retrievable values.

For example, I would like to display the customer name from the customer
table, but store the Customer ID which is available when an customer is
selected from the listbox.

Thanks


Apr 24 '06 #4
Thanks Cor.
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:et**************@TK2MSFTNGP04.phx.gbl...
Bill,

Dim dtIDA As New DataTable
dtIDA.Columns.Add("IDA", GetType(System.String))
dtIDA.Columns.Add("Description")
dtIDA.LoadDataRow(New Object() {"FQ", "Faqs"}, True)
dtIDA.LoadDataRow(New Object() {"DX", "DirextX"}, True)
dtIDA.LoadDataRow(New Object() {"LK", "Links"}, True)
dtIDA.DefaultView.Sort = "Description"
lstTitles.DataSource = dtIDA.DefaultView
lstTitles.DisplayMember = "Description"
lstTitles.ValueMember = "IDA"

Do you mean something as above

I hope this helps,

Cor
"bill" <be****@datamti.com> schreef in bericht
news:u7**************@TK2MSFTNGP03.phx.gbl...
Please direct me to a source which will explain how to populate a listbox
with retrievable values.

For example, I would like to display the customer name from the customer
table, but store the Customer ID which is available when an customer is
selected from the listbox.

Thanks


Apr 24 '06 #5
"bill" <be****@datamti.com> wrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
Please direct me to a source which will explain how to populate a listbox
with retrievable values.


The nice thing about the listbox is that the items property is just a
collection of objects. An ArrayList will do. When the listbox is rendered,
it the Framework calls ToString() on each object. Each object could be your
custom class with ID and CustomerName properties, or whatever you like. So
while databinding also works fine, it is really very flexible.

Tim
How stable is Visual Studio 2005?
http://www.itwriting.com/blog/?postid=414
Apr 24 '06 #6

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

Similar topics

2
by: James Goodman | last post by:
I have a listbox named sub1 on an asp page. I need to fill this list with values from a table. These are selected based upon the selection of a value/s in another listbox. It was suggested that I...
2
by: Wishing I was skiing mom | last post by:
Newbie to VB .NET. My solution contains an item maintenance screen, one of the fields on the screen is an item status, this field is defined as a listbox. The listbox item property contains a...
2
by: Yakimo | last post by:
I have a very simple application, consisting of a form and a listbox on it. I would like automatically to populate the listbox after the form is loaded and displayed, not using a button. But if I...
1
by: Devin Wood | last post by:
Hi, I have a page with a ListBox on it, and It's also have a some buttons to populate the ListBox by using JavaScript. I have no problem with populate the listbox using JavaScript. But when the...
3
by: Chris Kettenbach | last post by:
Hello all, Quick question. I have a listbox that is populated by items from a database. When the user select something from the list, I want to populate another listbox based on the selection in...
5
by: Arpan | last post by:
In order to populate any server control with data dynamically, is it ALWAYS NECESSARY to either BIND the DataSource to that server control or call the DataBind method of that server control? For...
4
by: Joe Blow | last post by:
Folks, I have read all the posts about databases I could find and I think I need a little more help. I want to take all the items from a field in an access database and use them as list items in...
1
by: Chaihana Joe | last post by:
Hi I'm trying to populate a listbox as a value list in code (access 2003). Unfortunately I'm getting 'runtime error 2176 - the setting for this property is too long' somewhere around the 2000...
2
by: dbuchanan | last post by:
I intend to populate a listBox from the database for later use. (the intent for doing this is irrelevant to this questrion) The list box when hidden is never populated. The list box when visible...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...
0
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...

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.