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

How do your read selected values from a BOUND ListBox in VB.Net

I have been trying to figure out for days on how to read values from a Bound
ListBox. The listBox gets the values from an Access Table.

I can read values fine for Non-Bound ListBoxes, But the same code doesn't
work for Bound, see below:

Any one of these work for a non-bound listbox.
Code:
'This get all items
For lnCnt = 0 To lstVolIssue.Items.Count - 1
lsVolIssue &= lstVolIssue.Items(lnCnt) & ","
Next

'These 2 methods get only the selected
For Each lsStr In lstVolIssue.SelectedItems
lsVolIssue &= lsStr.ToString
Next

For lnCnt = 0 To lstVolIssue.SelectedIndices.Count - 1
lsVolIssue = lsVolIssue &
lstVolIssue.Items(lstVolIssue.SelectedIndices.Item (lnCnt)).ToString & ","
Next


When using a BOUND listbox the 1st Code Segment
Code:

'This get all items
For lnCnt = 0 To lstVolIssue.Items.Count - 1
lsVolIssue &= lstVolIssue.Items(lnCnt) & ","
Next


Throws This exception
Cast from type 'DataRowView' to type 'String' is not valid.

The Second Code Segment
Code:

'These 2 methods get only the selected
For Each lsStr In lstVolIssue.SelectedItems
lsVolIssue &= lsStr.ToString
Next


Throws the same exception
Cast from type 'DataRowView' to type 'String' is not valid.

And the third segment
Code:

For lnCnt = 0 To lstVolIssue.SelectedIndices.Count - 1
lsVolIssue = lsVolIssue &
lstVolIssue.Items(lstVolIssue.SelectedIndices.Item (lnCnt)).ToString & ","
Next


Returns
System.Data.DataRowView,System.Data.DataRowView,Sy stem.Data.DataRowView,System.Data.DataRowView,

So it has to do with it being bound to a select statement that populates the
list.

HELP!!!

Richard

Nov 21 '05 #1
3 8434
Hi,

The bound list box will return a datarowview. The string you are
looking for is

Directcast(lstVolIssue.SelectedIndices.Item(lnCnt) ,datarowview).item("YourDisplayMember") Hope that helps.Ken--------------------------"Richard Albrecht" <Ri***************@RAlbrecht.net> wrote in messagenews:5v***************@newssvr33.news.prodi gy.com...I have been trying to figure out for days on how to read values from a BoundListBox. The listBox gets the values from an Access Table.I can read values fine for Non-Bound ListBoxes, But the same code doesn'twork for Bound, see below:Any one of these work for a non-bound listbox.Code:'This get all items For lnCnt = 0 To lstVolIssue.Items.Count - 1 lsVolIssue &= lstVolIssue.Items(lnCnt) & "," Next 'These 2 methods get only the selected For Each lsStr In lstVolIssue.SelectedItems lsVolIssue &= lsStr.ToString Next For lnCnt = 0 To lstVolIssue.SelectedIndices.Count - 1 lsVolIssue = lsVolIssue &lstVolIssue.Items(lstVolIssue.SelectedIndices.Ite m(lnCnt)).ToString & "," NextWhen using a BOUND listbox the 1st Code SegmentCode: 'This get all items For lnCnt = 0 To lstVolIssue.Items.Count - 1 lsVolIssue &= lstVolIssue.Items(lnCnt) & "," NextThrows This exceptionCast from type 'DataRowView' to type 'String' is not valid.The Second Code SegmentCode: 'These 2 methods get only the selected For Each lsStr In lstVolIssue.SelectedItems lsVolIssue &= lsStr.ToString NextThrows the same exceptionCast from type 'DataRowView' to type 'String' is not valid.And the third segmentCode: For lnCnt = 0 To lstVolIssue.SelectedIndices.Count - 1 lsVolIssue = lsVolIssue &lstVolIssue.Items(lstVolIssue.SelectedIndices.Ite m(lnCnt)).ToString & "," NextReturnsSystem.Data.DataRowView,System.Data.Dat aRowView,System.Data.DataRowView,System.Data.DataR owView,So it has to do with it being bound to a select statement that populates thelist.HELP!!!Richard

Nov 21 '05 #2
What is "YourDisplayMember" in:

Directcast(lstVolIssue.SelectedIndices.Item(lnCnt) ,datarowview).item("YourDisplayMember")

Thanks

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

The bound list box will return a datarowview. The string you are
looking for is

Directcast(lstVolIssue.SelectedIndices.Item(lnCnt) ,datarowview).item("YourDisplayMember")
Hope that helps.Ken--------------------------"Richard Albrecht"
<Ri***************@RAlbrecht.net> wrote in
messagenews:5v***************@newssvr33.news.prodi gy.com...I have been
trying to figure out for days on how to read values from a BoundListBox.
The listBox gets the values from an Access Table.I can read values fine
for Non-Bound ListBoxes, But the same code doesn'twork for Bound, see
below:Any one of these work for a non-bound listbox.Code:'This get all
items For lnCnt = 0 To lstVolIssue.Items.Count - 1 lsVolIssue &=
lstVolIssue.Items(lnCnt) & "," Next 'These 2 methods get only the
selected For Each lsStr In lstVolIssue.SelectedItems lsVolIssue &=
lsStr.ToString Next For lnCnt = 0 To
lstVolIssue.SelectedIndices.Count - 1 lsVolIssue = lsVolIssue
&lstVolIssue.Items(lstVolIssue.SelectedIndices.Ite m(lnCnt)).ToString & ","
NextWhen using a BOUND listbox the 1st Code SegmentCode: 'This get all
items For lnCnt = 0 To lstVolIssue.Items.Count - 1 lsVolIssue &=
lstVolIssue.Items(lnCnt) & "," NextThrows This exceptionCast from type
'DataRowView' to type 'String' is not valid.The Second Code SegmentCode:
'These 2 methods get only the selected For Each lsStr In
lstVolIssue.SelectedItems lsVolIssue &= lsStr.ToString NextThrows
the same exceptionCast from type 'DataRowView' to type 'String' is not
valid.And the third segmentCode: For lnCnt = 0 To
lstVolIssue.SelectedIndices.Count - 1 lsVolIssue = lsVolIssue
&lstVolIssue.Items(lstVolIssue.SelectedIndices.Ite m(lnCnt)).ToString & ","
NextReturnsSystem.Data.DataRowView,System.Data.Dat aRowView,System.Data.DataRowView,System.Data.DataR owView,So
it has to do with it being bound to a select statement that populates
thelist.HELP!!!Richard

Nov 21 '05 #3
Hi,

The field you are displaying in the listbox

Ken
------------------------
"Richard Albrecht" <Ri***************@RAlbrecht.net> wrote in message
news:iN***************@newssvr17.news.prodigy.com. ..
What is "YourDisplayMember" in:

Directcast(lstVolIssue.SelectedIndices.Item(lnCnt) ,datarowview).item("YourDisplayMember")

Thanks

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

The bound list box will return a datarowview. The string you are
looking for is

Directcast(lstVolIssue.SelectedIndices.Item(lnCnt) ,datarowview).item("YourDisplayMember")
Hope that helps.Ken--------------------------"Richard Albrecht"
<Ri***************@RAlbrecht.net> wrote in
messagenews:5v***************@newssvr33.news.prodi gy.com...I have been
trying to figure out for days on how to read values from a BoundListBox.
The listBox gets the values from an Access Table.I can read values fine
for Non-Bound ListBoxes, But the same code doesn'twork for Bound, see
below:Any one of these work for a non-bound listbox.Code:'This get all
items For lnCnt = 0 To lstVolIssue.Items.Count - 1 lsVolIssue &=
lstVolIssue.Items(lnCnt) & "," Next 'These 2 methods get only the
selected For Each lsStr In lstVolIssue.SelectedItems lsVolIssue &=
lsStr.ToString Next For lnCnt = 0 To
lstVolIssue.SelectedIndices.Count - 1 lsVolIssue = lsVolIssue
&lstVolIssue.Items(lstVolIssue.SelectedIndices.Ite m(lnCnt)).ToString & ","
NextWhen using a BOUND listbox the 1st Code SegmentCode: 'This get all
items For lnCnt = 0 To lstVolIssue.Items.Count - 1 lsVolIssue &=
lstVolIssue.Items(lnCnt) & "," NextThrows This exceptionCast from type
'DataRowView' to type 'String' is not valid.The Second Code SegmentCode:
'These 2 methods get only the selected For Each lsStr In
lstVolIssue.SelectedItems lsVolIssue &= lsStr.ToString NextThrows
the same exceptionCast from type 'DataRowView' to type 'String' is not
valid.And the third segmentCode: For lnCnt = 0 To
lstVolIssue.SelectedIndices.Count - 1 lsVolIssue = lsVolIssue
&lstVolIssue.Items(lstVolIssue.SelectedIndices.Ite m(lnCnt)).ToString & ","
NextReturnsSystem.Data.DataRowView,System.Data.Dat aRowView,System.Data.DataRowView,System.Data.DataR owView,So
it has to do with it being bound to a select statement that populates
thelist.HELP!!!Richard


Nov 21 '05 #4

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

Similar topics

8
by: Vipin Kedia | last post by:
Hi I have written a code for showing the list boxes as selected using a Listitem and the selected property of the items. Now I have 2 list boxes in my page. But it shows only the selected values...
3
by: RC | last post by:
I have a form where the user enters the Model info. The user picks the Model from either a combobox or listbox which both are filled from the Models table. If the Model type isn't in the boxes,...
2
by: Alpha | last post by:
How do I change the selected item in a listbox according to a Combox's selected item on the same form? The Combox is from a different table in the same dataset as the Listbox uses. Combox's...
0
by: Mardy | last post by:
Hello I'm using a multi select listbox that allows the user to select one or more values that are stored in a database. The listbox values are generated from a lookup table (disciplines) and the...
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...
0
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing...
2
by: John | last post by:
I have a listbox that is databound when my form loads. A user can then select and option using a drop down box. When the user selects an option the corresponding items in the listbox gets selected....
0
by: WB | last post by:
Hi, I have a ListBox in a Windows form. This ListBox contains a list of products for a user to choose. It's bound to a DataSet like this: listBox1.DataSource = dsProducts.Tables;...
0
by: awmb | last post by:
Language C#, Version ASP.Net 2.0 Hi I have a GridView which is bound to a table which contains Restaurant information. In the Edit Row there is a Listbox (ListBox1) in the Food Type column,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...

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.