473,394 Members | 1,739 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,394 software developers and data experts.

ListBox .DisplayMember and ValueMember ??

Hi all,

I got a problem of getting a display text and value from a item of a
listbox

Below is how I databind the data into myListBox

dt is a dataTable with 2 column, ID (int) and value (string)

Me.myListBox.DisplayMember = dt.Columns(1).ColumnName
Me.myListBox.ValueMember = dt.Columns(0).ColumnName
Me.myListBox.DataSource = dt

Now, I want to get the value out from myListBox:

For i As Integer = 0 To myListBox.Items.Count - 1
Dim li As ListItem
li.ItemData = lbChosenWork.Items.Item(i).Value <- I
want sth like this
li.Name = lbChosenWork.Items.Item(i).Text <- I want
sth like this
Next

However, methods .value and .text are not avaliable for me to use....

Anyone know the way to get the Display text of the item in myListBox?
Many thanks

Mar 27 '07 #1
1 11737
Rule #1 with winforms listboxes.

You don't put value pairs in the listbox.

You put OBJECTS into the listbox.

So if you're setting the datasource to a DataTable, then the OBJECTS in the
listbox are probably DataRows (or DataTableRows), and you need to get out a
DataRow or DataTableRow ..........

( I can't remember off hand)

but its something like this.
For i As Integer = 0 To myListBox.Items.Count - 1
dim dtr as DataTableRow = nothing
dtr = lbChosenWork.Items.Item(i)

' NOW You work with the dtr

Next

You'll have to figure out what object is in the listbox. Again, I emphasize
OBJECT, not

For i As Integer = 0 To myListBox.Items.Count - 1
dim o as object = nothing
o = lbChosenWork.Items.Item(i)

'' now look at the type of o .. or even the ToString method to
figure out what the exact object type is.

Next
<pe************@gmail.comwrote in message
news:11*********************@d57g2000hsg.googlegro ups.com...
Hi all,

I got a problem of getting a display text and value from a item of a
listbox

Below is how I databind the data into myListBox

dt is a dataTable with 2 column, ID (int) and value (string)

Me.myListBox.DisplayMember = dt.Columns(1).ColumnName
Me.myListBox.ValueMember = dt.Columns(0).ColumnName
Me.myListBox.DataSource = dt

Now, I want to get the value out from myListBox:

For i As Integer = 0 To myListBox.Items.Count - 1
Dim li As ListItem
li.ItemData = lbChosenWork.Items.Item(i).Value <- I
want sth like this
li.Name = lbChosenWork.Items.Item(i).Text <- I want
sth like this
Next

However, methods .value and .text are not avaliable for me to use....

Anyone know the way to get the Display text of the item in myListBox?
Many thanks

Mar 27 '07 #2

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

Similar topics

3
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm...
2
by: Supa Hoopsa | last post by:
Working on a windows form, I am trying to bind a listbox to a dataset and want to set the displaymember & Valuemember properties of the listbox so that I can retrieve the selectedvalue from a...
1
by: Irwin M. Fletcher | last post by:
ListBox DataSource DisplayMember Property Problems in C# I have a (single select) listbox with data and when I click on the list I can't get the right text selected. My listbox is setup...
1
by: Zoury | last post by:
Hi there! :O) I have a WebService that contains the following struct definition. this struct is defined right after the WebService class, ie : //*** namespace mynamespace { public class...
2
by: Alpha | last post by:
I have a window application. On one of the form, there is a listbox and a few combox. The lstSchItem has a dataview as a datasource. The comboxes are bind to its selected value but through the...
4
by: David Webster | last post by:
I have the following bit of code (which works fine): Dim Customer As New CCustomer mFrmOrder.lstCustID.DataSource = Customer.getCustomers.Tables("data") mFrmOrder.lstCustID.DisplayMember =...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
0
by: frank | last post by:
Hello, I have a listbox which is bound to a datatable. I have set the displaymember and valuemember and all works well: the user dbl clicks an item in the list box, I use the valuemember to...
2
by: frank | last post by:
Hello All, I know this is a re-post, but I didn't get any bites on my last post. So here goes again: I have a listbox which is bound to a datatable. I have set the displaymember and valuemember...
5
by: =?Utf-8?B?QmVu?= | last post by:
How would you add an item with its DisplayMember and ValueMember without binding to a datatable or dataview like: listbox.DisplayMember = "name"; listbox.ValueMember = "recid"; listbox.DataSource...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.