ALlow user to paste list of items into form

  • Thread starter Thread starter Microsoft
  • Start date Start date
M

Microsoft

I'm not sure which control to use for this:

I would like the user to be able to paste a list of items into a box and
then be able to run through them one at a time. Hopefully there is a
control that would place them into an array. I don't want the user to put
them in one at a time..

Thanks..
 
There isn't, that I know of, but you can easily write what you want. For
example, here's the code to let users paste a comma-delimited set of items
into a ListBox, where the user can then select them individually.

Dim data As IDataObject = Clipboard.GetDataObject()

' Determines whether the data is in a format you can use.
If data.GetDataPresent(DataFormats.Text) Then
' create an arraylist
' split comma-delimited items
Dim s As String = CType(data.GetData(DataFormats.Text), String)
Dim ar() As String = s.Split(","c)
Me.ListBox1.Items.Clear()
Me.ListBox1.Items.AddRange(ar)
Else
' No it is not.
MessageBox.Show("Could not retrieve data off the clipboard.")
End If

Obviously, you'd need to change the code and (sometimes) the target control
to paste other things, such as images, or a set of selected filenames.
 
OK.. I was able to get the results and get it into an array but I can;t
fiugure out the delimiter to use so that each line equals 1 array element

In the debug the data looks like it has one or two little squares betwwen
each value, but the data is in the Richtextbox like this

server1
server2
server3

Here is my code.. I can't get the delimiter right. It all ends up in
Serverarray(0)

Dim userdata As String

Dim serverarray As String()

Dim servercount As Integer

userdata = RichTextBox1.Text

serverarray = userdata.Split(vbCrLf)

Console.WriteLine(serverarray(2))



I get array out of bound because serverarray(0) is the entire textbox
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top