Jump to content

Listview and Updown-Input control


Recommended Posts

Hello guys, this is the script:

#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>

Global $hGUI = GUICreate("Test", 280, 400, -1, -1)
Global $cListview = GUICtrlCreateListView("NUMBER", 5, 5, 270, 272, BitOR($LVS_REPORT, $LVS_SINGLESEL))
Global $hListview = GUICtrlGetHandle($cListview)
Global $Input = GUICtrlCreateInput("100", 81, 304, 45, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
Global $UpDownInput = GUICtrlCreateUpdown(-1)
GUICtrlSetLimit(-1, 100, 1)

GUICtrlCreateListViewItem(45, $cListview)
GUICtrlCreateListViewItem(22, $cListview)
GUICtrlCreateListViewItem(70, $cListview)

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

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $tIndex, $tStruct
    $tStruct = DllStructCreate("hwnd;long;int;long;long", $ilParam)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch BitAND($iwParam, 0xFFFF)
        Case $UpDownInput
            If DllStructGetData($tStruct, 3) = 0xFFFFFD2E Then ; $UDN_DELTAPOS
                ConsoleWrite("Click")
;~              _GUICtrlListView_GetSelectedIndices($hListview)
            EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

What i want to do is:

a ) Select an item in the listview

b ) Click on the Updown control ( or write the numeric value in the input ) and edit the value in the listview selected item using WM_NOTIFY

The main problem is when i click on the input or the Updown control the selected item in the listview disappear, so i can't make any change.

Thanks for any help :D

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

  • Moderators

Terenz,

This looks as if it does what you want:

#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>

Global $fFlag = False

Global $hGUI = GUICreate("Test", 280, 400, -1, -1)
Global $cListview = GUICtrlCreateListView("NUMBER", 5, 5, 270, 272, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_EDITLABELS))
GUICtrlSetBkColor($cListview, 0x00FFCC)
Global $hListview = GUICtrlGetHandle($cListview)
Global $Input = GUICtrlCreateInput("100", 81, 304, 45, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
Global $UpDownInput = GUICtrlCreateUpdown(-1)
GUICtrlSetLimit(-1, 100, 1)

GUICtrlCreateListViewItem(45, $cListview)
GUICtrlCreateListViewItem(22, $cListview)
GUICtrlCreateListViewItem(70, $cListview)

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

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    If $fFlag Then
        $fFlag = False
        $iSelected = _GUICtrlListView_GetSelectedIndices($hListview)
        If $iSelected <> "" Then
            _GUICtrlListView_EditLabel($hListview, $iSelected)
            Sleep(100)
            Send(GUICtrlRead($Input) & "{ENTER}")
        EndIf
    EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $tIndex, $tStruct
    $tStruct = DllStructCreate("hwnd;long;int;long;long", $ilParam)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $iIDFrom
        Case $UpDownInput
            If DllStructGetData($tStruct, 3) = 0xFFFFFD2E Then ; $UDN_DELTAPOS
                $fFlag = True
            EndIf
    EndSwitch
    Switch $iCode
        Case $LVN_BEGINLABELEDITW
            Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
            Return False
        Case $LVN_ENDLABELEDITW
            Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
            Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _
                    DllStructGetData($tInfo, "Text"))
            Local $sNewText = DllStructGetData($tBuffer, "Text")
            If StringLen($sNewText) Then Return True
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Please ask if you have any questions. :)

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

An alternative ;)

; Johnmcloud + superuser Melba23 - 2014
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>

Global $fFlag = False

Global $hGUI = GUICreate("Test", 280, 400, -1, -1)
Global $cListview = GUICtrlCreateListView("NUMBER|Another Column", 5, 5, 270, 272, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS))
Global $hListview = GUICtrlGetHandle($cListview)
Global $Input = GUICtrlCreateInput("100", 81, 304, 45, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
Global $UpDownInput = GUICtrlCreateUpdown(-1)
GUICtrlSetLimit(-1, 100, 1)

GUICtrlCreateListViewItem("45|A text 0", $cListview)
GUICtrlCreateListViewItem("22|A text 1", $cListview)
GUICtrlCreateListViewItem("75|A text 2", $cListview)

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

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    If $fFlag Then
        $fFlag = False
        $iSelected = _GUICtrlListView_GetSelectedIndices($hListview)
        If $iSelected <> "" Then
            Local $sControl = ControlGetFocus($hGUI)
            _GUICtrlListView_SetItemText($hListview, $iSelected, ControlGetText($hGUI, "", $sControl), 0)
            Sleep(10)
        EndIf
    EndIf
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF)
    Local $iCode = BitShift($wParam, 16)
    If $iIDFrom = $Input And $iCode = $EN_CHANGE Then $fFlag = True
EndFunc   ;==>WM_COMMAND
Link to comment
Share on other sites

  • Moderators

johnmcloud,

Nice. :thumbsup:

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...