Copy listbox items to clipboard

Muchni

Member
Joined
Sep 30, 2008
Messages
18
Programming Experience
1-3
Im trying to copy items from listbox into my clipboard. The first word always works, but the rest just left blank. I am using this code
VB.NET:
  Dim ordning As Integer = 0
        Dim clip As String = ""
     
        If ordning < allanamn.Items.Count Then

            clip = allanamn.Items.Add(ordning)
            MsgBox(clip)
            My.Computer.Clipboard.SetText(clip)
            MsgBox(My.Computer.Clipboard.GetText)

            ordning += 1

        End If

And both msgboxes I put in shows what the clipboard should contain and both works correctly, but when I try to paste my clipboard, it wont show anything. I have tried different methods but never got this error, anyone knows a way to work around this?
 
Well I cannot write the code because I don't have Visual Studio Installed on this machine. But I can tell you that why only the first item is being copied. Your above code is executing only once, which is why it is copying only first item. In order to copy all items you need to loop that code.
 
I have the code in a button_click, and the integer is += 1 eveytime I click, isnt that enough? couse if I put it in a loop only the last will be copied, right?
 
In that case you will only get one item copied to the clipboard each time you click the button, not all the items.
 
wow i feel so stupid, the error was that when I read the lines from a .txt file they read a line too, so I pasted it in a textbox in vb and they are only 1 line so thats the reason why I couldnt see it
 

Latest posts

Back
Top