Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
 sid = ""
For Each st As String In ListBox1.SelectedItems

            If sid = "" Then
                sid = st
            Else
                sid += st
            End If

  Next
        MessageBox.Show(sid)

it is giving me an error :- Conversion from type 'DataRowView' to type 'String' is not valid.

how can i read SelectedItem or SelectedValues or Checkedvalues
i am using visual studio 2005
please help
Posted
Comments
Devang Vaja 28-Sep-12 5:33am    
First Of all You can Perform a loop For selected cheked items and make a string
than split string and use it Further

Extremely sorry the below code also works fine

VB
sid = ""
For Each st As String In ListBox1.SelectedItems

            If sid = "" Then
                sid = st
            Else
                sid += st
            End If

  Next
        MessageBox.Show(sid)


problem is i have set the datasource and displaymember property of ListBox in that case for and for-each loop don't work, i don't know why, if some one have any idea please share with us.
 
Share this answer
 
i done this with for loop
VB
Dim i As Integer
Dim str As String = ""

For i = 0 To ListBox1.SelectedItems.Count - 1
    str = str & " " & ListBox1.SelectedItems(i).ToString
Next
MessageBox.Show(str)


VB
Dim i As Integer
Dim str As String = ""

For i = 0 To CheckedListBox1.CheckedItems.Count - 1
    str = str & " " & CheckedListBox1.CheckedItems(i).ToString
Next
MessageBox.Show(str)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900