• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

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
0
Benvor
Asked:
Benvor
  • 4
  • 2
1 Solution
 
jpaulinoCommented:
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
 
jpaulinoCommented:
Humm, the list is bound to a datasource ... please ignore my last post
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jpaulinoCommented:

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
 
BenvorAuthor Commented:
That worked 100% thanx allot jpaulino
0
 
jpaulinoCommented:
Glad I could help!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now