Home All Groups Group Topic Archive Search About

vb.net 2005 - how to populate a listbox

Author
24 Apr 2006 1:28 PM
bill
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

Author
24 Apr 2006 1:36 PM
Steve Lloyd
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.


Show quoteHide quote
"bill" <bel***@datamti.com> wrote in message
news:u7LExL6ZGHA.1196@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
>
>
Author
24 Apr 2006 2:55 PM
bill
Thanks!

Show quoteHide quote
"Steve Lloyd" <steve.rem***@livenowpaylater.this.co.uk> wrote in message
news:uf$ZPQ6ZGHA.508@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" <bel***@datamti.com> wrote in message
> news:u7LExL6ZGHA.1196@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
>>
>>
>
>
Author
24 Apr 2006 2:07 PM
Cor Ligthert [MVP]
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


Show quoteHide quote
"bill" <bel***@datamti.com> schreef in bericht
news:u7LExL6ZGHA.1196@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
>
>
Author
24 Apr 2006 3:11 PM
bill
Thanks Cor.
Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:etkr9g6ZGHA.3880@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" <bel***@datamti.com> schreef in bericht
> news:u7LExL6ZGHA.1196@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
>>
>>
>
>
Author
24 Apr 2006 4:49 PM
Tim Anderson
"bill" <bel***@datamti.com> wrote in message
news:u7LExL6ZGHA.1196@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