Problem with adding listbox Items as String to Array

Hi Experts

I have an application that I use to send "net send" message across the network, but now I want to be able to send 1 message to more than 1 user. I have a listbox(lbUserNames) that I populate with user names from an Access database on my FormLoad event. Then the lisbbox's Selection mode = MultiSimple ( so I can choose how many people I want to send the message to). I tried to load all the selected items into an array, but I get an error "Conversion from type 'DataRowView' to type 'String' is not valid'". I now that my array works, because I tested it with a listbox that doesn't have a datasource and it worked.

Please can anyone tell me how to add the Items into the Array.

Thanx in advance

Try
            Dim i As Integer = lbUserNames.SelectedItems.Count - 1
            Dim Username As String
 
 
            Dim items() As Object = New ArrayList(lbUserNames.SelectedItems).ToArray
            MessageBox.Show("Length: " & items.Length)
            For Each Username In items
 
                Try
                    Microsoft.VisualBasic.Shell("net send " & Username & " " & message)
                Catch ex As Exception
                    MessageBox.Show(ex.Message.ToString())
                End Try
            Next
 
 
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())
        End Try

Open in new window

untitled.bmp
BenvorAsked:
Who is Participating?
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:

To late :)

Try this way then

        Try
 
            Dim selectedItems As ListBox.SelectedObjectCollection = lbUserNames.SelectedItems
            Dim dv As DataRowView = Nothing
            For x As Integer = 0 To selectedItems.Count - 1
 
                Try
                    dv = selectedItems.Item(x)
                    Microsoft.VisualBasic.Shell("net send " & dv.Item(0).ToString & " " & Message)
 
                Catch ex As Exception
                    MessageBox.Show(ex.Message.ToString())
                End Try
            Next
 
 
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())
        End Try

Open in new window

0
 
Jorge PaulinoIT Pro/DeveloperCommented:
But why you need that ? You can do this way:
        Try
 
            For Each Username As String In lbUserNames.SelectedItems
                Try
                    Microsoft.VisualBasic.Shell("net send " & Username & " tvvxc")
                Catch ex As Exception
                    MessageBox.Show(ex.Message.ToString())
                End Try
            Next
 
 
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())
        End Try

Open in new window

0
 
BenvorAuthor Commented:
I've tried that before but also got the "Conversion from type 'DataRowView' to type 'String' is not valid'" Error, so I tried using an array and thought it might work... But it didn't
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Jorge PaulinoIT Pro/DeveloperCommented:
Humm, the list is bound to a datasource ... please ignore my last post
0
 
BenvorAuthor Commented:
That worked 100% thanx allot jpaulino
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Glad I could help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.