Copy / Paste items from a list into any document (Excel, Word, .txt) - VB.NET

I can not copy / paste elements from my list into any document (Excel, Word, .txt). I will need to select several items in the list. I searched for it, but there seem to be a few vague answers. Can anyone guide me?

Thanks!

+4
source share
2 answers

All you have to do is enable SelectionMode to MultiSimple or MultiExtended , then you can use the SelectedItems collection to copy to the clipboard in the KeyDown event from the list.

Simply put

ListBox1.SelectionMode = SelectionMode.MultiSimple in form.load Event

and use this code (note: listbox is called ListBox1 )

 Private Sub ListBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown If e.Control AndAlso e.KeyCode = Keys.C Then Dim copy_buffer As New System.Text.StringBuilder For Each item As Object In ListBox1.SelectedItems copy_buffer.AppendLine(item.ToString) Next If copy_buffer.Length > 0 Then Clipboard.SetText(copy_buffer.ToString) End If End If End Sub 
+11
source

Paste rich text and add the following:

 For x As Integer = 0 To ListBox1.Items.Count - 1 RichTextBox1.AppendText(ListBox1.Items(x).ToString & Environment.NewLine) Next 
0
source

All Articles