I want to paste data from the clipbord in a vb.net using this code:
Private Sub MenuItemPaste_Click(sender As Object, e As EventArgs) Handles MenuItemPaste.Click
Dim items() As String = Clipboard.GetText.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) '
ListBox1.Items.AddRange(items)
Why Does the selected text is pasted 2 times?
Your code seems correct and there is no reason to paste the text twice! I guess you need to clear the ListBox1
first before adding text to it in the MenuItemPaste_Click
event. So you can try using the following code :
ListBox1.Items.Clear()
Dim items() As String = Clipboard.GetText.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) '
ListBox1.Items.AddRange(items)