Jump to content

Recommended Posts

Posted

I've got a beautifully cheesy GUI for gathering some data from remote computers for User Support.

Now... How can I make it where User Support guys can select the text and Copy it to their clipboard??

Specifically, I have a ListView control that lists out a bunch of helpful information that would be nice for them to copy and paste into a trouble ticket.

Is that possible... ?

Posted

Not sure exactly how to do it with a list view, but if this is customer support, a useful tool would be to take a screenshot of the remote computer and send it to the support guy so he can see the text. Just an idea.

Posted

Hi,

Yep there's a few way it can be done.

I tried it as a context menu "copy".

Offered singe or multi select copy.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $iLV, $iCtxt0, $iCtxt1, $msg, $iSelCnt, $sTmp
    GUICreate(":-)", 400, 300)
    $iLV = GUICtrlCreateListView("Item #|Data 1|Data 2", 5, 5, 390, 290, $LVS_SHOWSELALWAYS)
    $iCtxt0 = GUICtrlCreateContextMenu($iLV)
    $iCtxt1 = GUICtrlCreateMenuItem("Copy", $iLV)
    For $i = 1 To 5
        GUICtrlCreateListViewItem($i & "|Item " & $i & "'s Data 1|Item " & $i & "'s Data 2", $iLV)
    Next
    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $iCtxt1
                $iSelCnt = _GUICtrlListView_GetSelectedCount($iLV)
                Switch $iSelCnt
                    Case 1
                        ClipPut(_GUICtrlListView_GetItemTextString($iLV))
                    Case 2 To $iSelCnt
                        $sTmp = ''
                        For $i = 1 To UBound(_GUICtrlListView_GetSelectedIndices($iLV, True)) - 1
                            $sTmp &= _GUICtrlListView_GetItemTextString($iLV, $i - 1) & @CRLF
                        Next
                        ClipPut(StringStripWS($sTmp, 2))
                EndSwitch
        EndSwitch
    WEnd
EndFunc   ;==>Example
Cheers
Posted (edited)

Hi,

Yep there's a few way it can be done.

I tried it as a context menu "copy".

Offered singe or multi select copy.

Thank you! Put me on the right track!

I altered the code a bit to get it to work just right (for my purposes).

Func CopyText()
    Local $msg, $iSelCnt, $sTmp

    $iSelCnt = _GUICtrlListView_GetSelectedCount($List1)
    Switch $iSelCnt
        Case 0
            For $i = 0 To _GUICtrlListView_GetItemCount($List1) - 1
                $sTmp &= _GUICtrlListView_GetItemTextString($List1, $i) & @CRLF
                ClipPut($sTmp)
            Next
        Case 1
            ClipPut(_GUICtrlListView_GetItemTextString($List1))
        Case 2 To $iSelCnt
            $sTmp = ''
            For $i = 1 To UBound(_GUICtrlListView_GetSelectedIndices($List1, True)) - 1
                $sTmp &= _GUICtrlListView_GetItemTextString($List1, $i - 1) & @CRLF
            Next
            ClipPut($sTmp)
    EndSwitch

EndFunc   ;==>CopyText

Oh, and put in an nice little button to activate the copy....

; Copy text button ---->
Global $copytext = GUICtrlCreateButton("Copy Text", 270, 536, 75, 20)
GUICtrlSetOnEvent($copytext, "CopyText")
;<-------- Copy text button

Can copy the whole list or the selection. I haven't been able to select more than one line item though... *shrug*

Edited by Graywalker
Posted

..... I haven't been able to select more than one line item though... *shrug*

Hi, your welcome and glad to hear you got it worked out.

For multi select of item you'll need to set the control style.

Default autoit uses BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL) as the style.

That was why I just used $LVS_SHOWSELALWAYS as the style on it's own :)

Cheers

  • 3 years later...
Posted

I just wanted to say that this is the absolute first search result I got in Google and I don't know why... so I absolutely need to share my ListView clipboard so others could take the code and not have to dig for hours. Just trying to help folks get there quicker. My listview variable is "$ListViewSP01" so you'll need to change it to your own...

Here's the button...

Global $copytext = GUICtrlCreateButton("Copy To Clipboard", 75, 25, 125, 20)

Put this in your gui switch statement:

Case $copytext

_CopyText01()

Calls this function - copies listview data to the clipboard for pasting :)

Func _CopyText01()
; Read all Inputs on Form
;MsgBox(4160, "TEST", "Selected Item from List is: " & _GUICtrlListView_GetSelectedIndices($ListViewSP01, False))
Local $aSelcted, $aDdata
$aSelcted = _GUICtrlListView_GetSelectedIndices($ListViewSP01, True)
If $aSelcted[0] > 0 Then
Dim $aDdata[$aSelcted[0] + 1]
$aDdata[0] = $aSelcted[0]
For $i = 1 To $aSelcted[0]
$aDdata[$i] = _GUICtrlListView_GetItemTextString($ListViewSP01, $aSelcted[$i])
Next
EndIf
If IsArray($aDdata) Then
_ArrayDelete ($aDdata, 0)
ClipPut (_ArrayToString($aDdata, @CRLF))
EndIf
Endfunc

This took me a couple hours to nail down so I hope I help someone out there searching for the same keywords.

"Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"
Song Title: I guess you could say
Artist: Middle Class Rut

  • 11 months later...
Posted

to make it work with events , i did the following

 1) create a list view

Local $__style = BitOR($WS_BORDER,$LVS_SHOWSELALWAYS);$LVS_SHOWSELALWAYS  $LVS_SORTDESCENDING,$WS_THICKFRAME ,$LVS_EDITLABELS $LVS_REPORT,$LVS_SINGLESEL,
    Local $__WsExStyle = 0
    $L_Report_log = GUICtrlCreateListView("A|B|C|D|E|F|G|H|I|J|K|L|M|N", 5, $top, $wide-20, $high-$top-30,$__style,$__WsExStyle)
    GUICtrlRegisterListViewSort($L_Report_log, "LVSortReport") ; Register the function "SortLV" for the sorting callback
    Local $__CtrlExStyle = BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT,$LVS_EX_ONECLICKACTIVATE)   ;,$LVS_EX_HEADERDRAGDROP
    GUICtrlSendMsg(-1,$LVM_SETEXTENDEDLISTVIEWSTYLE,$__CtrlExStyle,$__CtrlExStyle)
    GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

    $iCtxt0 = GUICtrlCreateContextMenu($L_Report_log)
    $iCtxt1 = GUICtrlCreateMenuItem("Copy", $L_Report_log)

2) register the event form

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

3) inside the WM_COMMAND









Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)  ; Handle WM_COMMAND messages  ;---------------------    Local $nNotifyCode = _HiWord($iwParam)    Local $nID = _LoWord($iwParam) ;ConsoleWrite("+$nID" & $nID & @CRLF) ;ConsoleWrite("--$iMsg" & $iMsg & @CRLF)  Switch $nID Switch $iSelCnt
        Case 1
            ConsoleWrite("++case1"  &@crlf)
            ClipPut(_GUICtrlListView_GetItemTextString($L_Report_log))
        Case 2 To $iSelCnt
            ConsoleWrite("++case2"  &@crlf)
            $r=_GUICtrlListView_GetSelectedIndices($L_Report_log, True)
            ;_ArrayDisplay($r )
            $sTmp = ''
            For $i = 1 To $r[0]
                $sTmp &= _GUICtrlListView_GetItemTextString($L_Report_log, $r[$i]) & @CRLF
            Next
        $sTmp=StringReplace($sTmp,"|",@TAB)
        ClipPut(StringStripWS($sTmp, 2))
    EndSwitch
endfunc
 

hope this help

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...