Jump to content

Listview takes 2 clicks to copy text to input box


Recommended Posts

Here is the code:

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("TrayIconDebug",1)
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <GuiListView.au3>

Func GetLatestPreviousFilspcs()
; Much simplified for AutoIt forum
Local   $retVec[3]
    $retVec[0] = "cat"
    $retVec[1] = "dog"
    $retVec[2] = "goat"
    Return $retVec
EndFunc

Local $frmSelFromPrev = GUICreate("Select based on previous files", 623, 501, 192, 114)
Local $style = BitOR($LVS_LIST,$LVS_SHOWSELALWAYS,$LVS_SINGLESEL,$LVS_SORTASCENDING)
Local $hListView = GUICtrlCreateListView("", 8, 8, 593, 361, $style)
Local $btnOK = GUICtrlCreateButton("OK", 424, 448, 49, 25)
Local $btnCancel = GUICtrlCreateButton("Cancel", 488, 448, 65, 25)
Local $Input1 = GUICtrlCreateInput("", 96, 384, 305, 21)
Local $ctrlExStyles = $LVS_EX_ONECLICKACTIVATE
GUICtrlSendMsg(-1, $LVM_SETEXTENDEDLISTVIEWSTYLE,$ctrlExStyles,$ctrlExStyles)

Local $itemvec = GetLatestPreviousFilspcs()
For $i = 0 to ubound($itemvec)-1
    GUICtrlCreateListViewItem($itemvec[$i],$hListView)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)

Local $nMsg,$Index=999
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE,$btnCancel
            ExitLoop
        Case $btnOK
            MsgBox(0, "input control", GUICtrlRead($Input1), 2)
             ExitLoop
    EndSwitch
WEnd
GUIDelete($frmSelFromPrev)

;~ ========================================================
;~ This thing is responsible for click events
;~ ========================================================
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_ITEMACTIVATE ; Sent by a list-view control when the user clicks an item with the left mouse button
                 Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                 $Index = DllStructGetData($tInfo, "Index")
;                Local $subitemNR = DllStructGetData($tInfo, "SubItem")
                 If $Index <> -1 Then
                             GUICtrlSetData($Input1,_GUICtrlListView_GetItemText($hWndListView,$Index))
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

In my code, there are about 100 list items. but the above code demonstrates the problem.

I want to do something like FileSaveDialog(), where single-clicking on an item copies the text of the item to the input box.

But the above code requires two clicks to do the copy.

I would appreciate any guidance you can give me on achieving single-click copying.

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

  • Moderators

c.haslam,

In my experience using a single click to action something when dealing with a ListView is not a good idea as the ListView often "eats" the single click to select the item rather than acting upon it as you wish. Using a double click is a much better option - I would stick with what you have got at the moment. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks, Melba23. I can live with 2 clicks, but I do wonder how FileSaveDialog() does it. Perhaps the answer is: it's not written in AutoIt!

A second question about this code:

I have now made a function out of the GUI..() stuff and the message loop, but I am now getting "possibly used before declaration." for $Input 1 and $hListview.

I know that I can overcome these warnings by making these variables global, but is there a way of forcing WM_NOTIFY() to see $Input1 with Opt("MustDeclareVars",1) ? And the same for $hListView?

I think I knew the answer a long time ago, but have forgotten it.

...chris

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

  • Moderators

c.haslam,

Not that I know of. If you want variables to be visible across function boundaries then they have to be Global in scope. :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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