ListView items copy to clipboard

Greetings,

I have a ListView control (in Report view, with a entire line section) with 10 or more lines and 6 columns. Now I wish to add a Copy function that will copy the selected lines (and all of the sub items) to clipboard in this format: assuming lines 1, 2 and 3 are selected.

Line1
A B C D E

Line 2
A B C D E

Line 3
F G H I J

How can I accomplish this?

Thanks1
LVL 34
sramesh2kAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ShauliConnect With a Mentor Commented:
Private Sub Command1_Click()
Dim tLoop As Integer, mLoop As Integer, toClip As String, tmpSel As String
Clipboard.Clear
For tLoop = 1 To ListView1.ListItems.Count
    If ListView1.ListItems(tLoop).Selected Then
        tmpSel = ListView1.ListItems(tLoop).Text
        For mLoop = 1 To ListView1.ColumnHeaders.Count - 2
                tmpSel = tmpSel & chr(32) & ListView1.ListItems(tLoop).ListSubItems(mLoop).Text
        Next mLoop
        toClip = toClip & tmpSel & vbNewLine
    End If
Next tLoop
Clipboard.SetText toClip
End Sub

S
0
 
sramesh2kAuthor Commented:
It works! Thanks, Shauli.
0
All Courses

From novice to tech pro — start learning today.