Click here to Skip to main content
12,512,548 members (25,523 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB8.0 VB VB.NET
 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 27-Sep-12 23:28pm
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Extremely sorry the below code also works fine

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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

i done this with for loop
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)

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)
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100