|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How do your read selected values from a BOUND ListBox in VB.NetListBox. 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 Almost everybody in this newsgroup is using VB6 or lower. While you may
get a stray answer to VB.NET (including VB2003 and VB2005 which has dropped .NET from its name) questions here, you should ask them in newsgroups devoted exclusively to .NET programming. Look for newsgroups with either the word "dotnet" or "vsnet" in their name. For the microsoft news server, try these newsgroups for Visual Basic ..NET related questions... microsoft.public.dotnet.languages.vb microsoft.public.dotnet.languages.vb.upgrade microsoft.public.dotnet.languages.vb.controls microsoft.public.dotnet.languages.vb.data And these for more general .NET questions microsoft.public.dotnet.general microsoft.public.vsnet.general Note: There are many other .NET newgroups (use the first three "fields" from the last two as templates when searching for them), but the above ones should get you started. Rick - MVP Show quoteHide quote "Richard Albrecht" <RichSpamNotWanted@RAlbrecht.net> wrote in message System.Data.DataRowView,System.Data.DataRowView,System.Data.DataRowView,news:N15le.1687$uu.1456@newssvr33.news.prodigy.com... > 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, Show quoteHide quote > > So it has to do with it being bound to a select statement that populates the > list. > > HELP!!! > > Richard > > |
|||||||||||||||||||||||