cgaDesign
asked on
VB.NET Winforms Multiselect Listbox Traverse ?
In vb.net 2005, winforms, how do you traverse a multiselect Listbox ? I need to extract the selected values, and build a SQL Select statement. I can write the loop, but Listbox.Selected() is not recognized (must be for Webforms). Thank you.
ASKER
No ... that example refers to Classic ASP ... I am using VB.NET WinForms.
Dim strWhere As String = "WHERE sClass IN("
Dim i As Integer = 0
Dim str As String = ""
For i = 0 To ListBox1.SelectedItems.Count - 1
strWhere &= "'" & ListBox1.SelectedItems(i).ToString() & "',"
Next
strWhere = strWhere.TrimEnd(",") & ")"
ASKER
The value of my strWhereUnit variable becomes, during output:
Or P.intUnitFK = 'System.Data.DataRowView'
for each Selected Item. I am supposed to get integers as values.
Dim strWhere As String = ""
For i = 0 To Me.lstLkUnit.SelectedItems .Count - 1
strWhereUnit += " Or P.intUnitFK = '" + Me.lstLkUnit.SelectedItems (i).ToStri ng() + "'"
Next i
Thank you
Or P.intUnitFK = 'System.Data.DataRowView'
for each Selected Item. I am supposed to get integers as values.
Dim strWhere As String = ""
For i = 0 To Me.lstLkUnit.SelectedItems
strWhereUnit += " Or P.intUnitFK = '" + Me.lstLkUnit.SelectedItems
Next i
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, that worked. Guess I need to look up CType, and bound Listboxes. My Listbox is actually bound to a bindingsource object. This probably should have been worth more points ...
Thanks much !
Thanks much !
ASKER
The essence was that I needed to realize that I was traversing a DATABOUND Listbox.
ASKER
The essence to the problem was that I needed to realize that I was trying to traverse a DATABOUND Winforms Listbox.
https://www.experts-exchange.com/questions/22652161/VB-net-ListBox-multi-select.html