R
Richard Albrecht
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,System.Data.DataRowView,System.Data.DataRowView,
So it has to do with it being bound to a select statement that populates the
list.
HELP!!!
Richard
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,System.Data.DataRowView,System.Data.DataRowView,
So it has to do with it being bound to a select statement that populates the
list.
HELP!!!
Richard