• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

Copy data out of a listview

I want to be able to copy selected rows  or columns out a listview to the clipboard then be able to paste the resuts into excel and have the data inserted in the colums so it is formatted  the same way

so if the listview is like this
data 1 |  data2  | data 3
row2a |  data2  | data 3
 
I want to be able to highlight those 2 rows in the listview and copy them  then paste them into excel or whatever and have them formatted in the rows and colums that were in the listview.

Is there an easy way to do this?

Kelly



0
unreal400
Asked:
unreal400
1 Solution
 
plqCommented:
           If Screen.ActiveControl Is lvw Then
                For Each itm In lvw.ListItems
                    If itm.Selected Then
                        sBuffer = sBuffer & Mid$(itm.Key, 2) & vbTab
                        For lCount = 0 To lvw.ColumnHeaders.Count - 1
                            If lCount = 0 Then
                                sValue = itm.Text
                            Else
                                sValue = itm.SubItems(lCount)
                            End If
                            sBuffer = sBuffer & sValue & vbTab
                        Next
                        sBuffer = sBuffer & vbCrLf
                    End If
                Next
            End If
           
            If sBuffer = "" Then
                MsgBox "No items are selected. Use CTRL and Click or Shift and Click to select the items you want to copy", vbExclamation
            Else
                Clipboard.Clear
                Clipboard.SetText sBuffer
            End If
0
 
aelatikCommented:
Private Sub Form_Load()
    Clipboard.Clear
For i = 1 To 3
    ListView1.ListItems.Add , , "test"
    ListView1.ListItems.Item(i).SubItems(1) = "test1" & i
    ListView1.ListItems.Item(i).SubItems(2) = "test2" & i
Next i
   
    Dim BUFFER
    For i = 1 To ListView1.ListItems.Count
        BUFFER = BUFFER & ListView1.ListItems.Item(i).Text & vbTab & ListView1.ListItems.Item(i).SubItems(1) & vbTab & ListView1.ListItems.Item(i).SubItems(2) & vbCrLf
    Next i
        Clipboard.SetText BUFFER
End Sub
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now