9/19/2011

VB.Net : Copy data listview to clipboard in VB.NET

Copy all data in listview.

Code Example :
Imports System.Text

.......

Public Sub CopyListViewToClipboard(ByVal lv As ListView)
        Dim buffer As New StringBuilder

        For i As Integer = 0 To lv.Columns.Count - 1
            buffer.Append(lv.Columns(i).Text)
            buffer.Append(vbTab)
        Next

        buffer.Append(vbCrLf)

        For i As Integer = 0 To lv.Items.Count - 1
            For j As Integer = 0 To lv.Columns.Count - 1
                buffer.Append(lv.Items(i).SubItems(j).Text)
                buffer.Append(vbTab)
            Next
            buffer.Append(vbCrLf)
        Next

        My.Computer.Clipboard.SetText(buffer.ToString)

    End Sub

**** You use call function
Example : call CopyListViewToClipboard(name ListView)

No comments:

Post a Comment