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

Retrieving selectedvalue in multiselect listbox problem

IMK
Hello all,
Sorry if this issue has come up already but I am new to vb.net.
Thanks.

I am trying to retrieve the selectedvalues from a multiselect list box
in a vb 2005 winform. Here is the code I am using so far:

dim i as object

For Each i In Me.lstUnitPicklist.SelectedItems
MessageBox.Show(Me.lstUnitPicklist.SelectedValue)
Next

Eventually I will replace the messagebox with the name of a sub that
will take the selectedvalue as a parameter.

The problem is that, as the code goes through each selected item, it
returns only the first selected value repeatedly for the number of
selected items.
In other words, If the listbox was a listbox of colors and I had
selected "blue", then "green" then "yellow" the code would show
"blue", "blue", "blue" then stop.

I have used similar code before and it worked fine. Is there another
way to do this? It seems so simple, but I am stumped.

Mar 19 '07 #1
1 3175
IMK
D'oh

I must remember to use Google's wonderful "Search this group"
functionality
before I post. I found this from MVP Luke Zhang from several years
ago:

Here is the sample code for a work around:
Dim dview As DataRowView
For Each dview In ListBox1.SelectedItems
MsgBox(dview.Row.Item(0).ToString)
Next

That's all I needed. Thanks MVPs

Mar 19 '07 #2

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

Similar topics

2
by: Alex A via .NET 247 | last post by:
Hello all. I'm new to .NET and I am stuck and I just cannot getthis to work (even after much searching). I have a listbox populated by data from an Access Database. Themanner in which I fill the...
6
by: Dave Hopper | last post by:
Hi I am using the following SQL to retrieve a value in a list box using a unique ID held in the list box call cntID. The list box is used on an order form to list appointments that have been...
2
by: bill yeager | last post by:
I need to get the SelectedValue of each item selected in a multi-selection listbox. I have the following code, but it just returns me the SelectedValue of ONLY the first item selected in the list:...
4
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox),...
1
by: Tony Dong | last post by:
Hi there I have one multiselect listbox, and get date from database using DataSet HolidaysListBox.ValueMember = "HolidayDate" HolidaysListBox.DisplayMember = "HolidayName"...
3
by: David L Wright II | last post by:
I have a data bound listbox that I want to select multiple lines then process each line. I bound a two column datatable to the listbox and set the DisplayMember property to the appropriate column...
3
by: kaosyeti via AccessMonster.com | last post by:
hey... i have an unbound multiselect listbox on a form that i want to use to populate text boxes on that form. so if a user selects the 3rd item in a list of 20, how can i have that item show up...
2
by: =?Utf-8?B?U3RlcGhlbiBSaXRjaGll?= | last post by:
Hi NET1.1 / Winforms I have a listbox that I am binding to a table via the DataSource property. However I want to be able to programmatically select values in this listbox so I am using the...
0
by: Phijo | last post by:
Hello, I'm a Java developer but brand new to ASP (i have done some of the tutorials) so I have some ASP programming background however I cannot find the cause or the fix to this problem. I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.