Jump to content

I want to edit a listview item


Martino
 Share

Recommended Posts

I read about _GUIListViewEx_SetEditStatus with $iMode = 9 but I find it hard to understand.

 

Somewhere i found this code.

#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>

$Form = GUICreate('', 600, 600)
$ListView = GUICtrlCreateListView(' ', 10, 10, 280, 580, BitOR($LVS_NOCOLUMNHEADER, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
$hListView = GUICtrlGetHandle($ListView)
_GUICtrlListView_SetColumnWidth($ListView, 0, 258 + 100)
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState()

$FileList = _FileListToArray('C:\WINDOWS\system32', '*.ini', 1)
For $i = 1 To $FileList[0]
    GUICtrlCreateListViewItem($FileList[$i], $ListView)
Next

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case 0
            ContinueLoop
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $tNMHDR = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom')
    Local $Index = DllStructGetData($tNMHDR, 'Index')
    Local $Code = DllStructGetData($tNMHDR, 'Code')

    Switch $IDFrom
        Case $ListView
            Switch $Code
            Case $LVN_ITEMCHANGED
                $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
                ; if state has changed
                If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _
                    DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then
                    ; take care of only newly selected items (not deselected ones)
                    If BitAND(DllStructGetData($NMLISTVIEW, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED  Then
                        $Item = _GUICtrlListView_GetItem($ListView, $Index)
                        ConsoleWrite($Item[3] & @CR)
                    EndIf
                EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

and i can understand it also a little bit more.

I integrated it in my code

#include <GUIConstantsEx.au3>

#include <GUIListViewEx.au3>

Global $GuiSamenvatting = GUICreate("Gui", 1500, 600)

Global $btn_Verplaats = GUICtrlCreateButton(" save", 1250, 10, 150)
GUICtrlSetState($btn_Verplaats, $GUI_ENABLE)

$idListview = GUICtrlCreateListView("#  | FILES  | PROJECTCODE | DOCNR | DOCCODE | DOCSOORT | DOELLOCATIE  ", 10, 10, 1200, 450) ;,$LVS_SORTDESCENDING)
For $n = 1 To 10 ;  $aantgevondenpdfen
    GUICtrlCreateListViewItem($n & "|" & $n & "|" & $n & "|" & $n & "|" & $n & "|" & $n & "|" & $n, $idListview)
Next
_GUICtrlListView_SetColumnWidth($idListview, 1, 250)
_GUICtrlListView_SetColumnWidth($idListview, 2, 100)
_GUICtrlListView_SetColumnWidth($idListview, 3, 70)
_GUICtrlListView_SetColumnWidth($idListview, 4, 100)
_GUICtrlListView_SetColumnWidth($idListview, 5, 150)
_GUICtrlListView_SetColumnWidth($idListview, 6, 450)

;If $AndereExtGevonden = 1 Then
;GUICtrlCreateLabel("Andere bestandsextensies: " & $andereextensies , 800, 50, 300, 25)
;EndIf

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

Global $aLV_Content = _GUIListViewEx_ReadToArray($idListview)
Global $iLV_Index = _GUIListViewEx_Init($idListview, $aLV_Content, 0, 0, True, 32)
_GUIListViewEx_SetEditStatus($iLV_Index, "2") ; Project column editable maken
_GUIListViewEx_SetEditStatus($iLV_Index, "3") ; doc NR column editable maken
_GUIListViewEx_SetEditStatus($iLV_Index, "4") ; Doc type column editable maken
_GUIListViewEx_MsgRegister()

; Loop until the user exits.
Do
    Local $ArrayMetItemsListView = _GUIListViewEx_EventMonitor() ; Allow the UDF to monitor events

    $Msg = GUIGetMsg()
    Switch $Msg
        Case 0
            ContinueLoop
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    If Not @error Then ; There was no error detected

        Switch @extended
            Case 1 ; Standard edit mode
                Local $ErIsIetsFout = 0
                If $ArrayMetItemsListView <> "" Then ; If edit not aborted
                    If $ArrayMetItemsListView[1][1] = 2 Then
                        Local $IngevoerdeCode = $ArrayMetItemsListView[1][3]
                        Local $AangepasteLijn = $ArrayMetItemsListView[1][0] + 1

                        ;$arr_gevondenprojectcode[$AangepasteLijn]= $IngevoerdeCode

                        GUISetState(@SW_HIDE, $GuiSamenvatting)
                        GUIDelete($GuiSamenvatting)
                        ;MaakGuiSamenvatting ()
                    EndIf
                EndIf
        EndSwitch

    EndIf

Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $tNMHDR = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom')
    Local $Index = DllStructGetData($tNMHDR, 'Index')
    Local $Code = DllStructGetData($tNMHDR, 'Code')

    Switch $IDFrom
        Case $idListview
            Switch $Code
            Case $LVN_ITEMCHANGED
                $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
                ; if state has changed
                If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _
                    DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then
                    ; take care of only newly selected items (not deselected ones)
                    If BitAND(DllStructGetData($NMLISTVIEW, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED  Then
                        $Item = _GUICtrlListView_GetItem($idListview, $Index)
                        ConsoleWrite($Item[3] & @CR)
                    EndIf
                EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

But then in my console i receive the text of the item in the first column but the others column are not editable anymore.

Am i placing the
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') wrong or is it not possible to combine it with _GUIListViewEx_MsgRegister() ?

Strange that it's so hard to catch a click or a double click on a listitem.

 

 

 

 

 

Link to comment
Share on other sites

I simplyfied my code

So now i receive a message in my console but i'm not able to edit the 3th column anymore.

#include <File.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include "GUIListViewEx.au3"
#include <Misc.au3>

Global $FileArray[11]
Global $CodeArray[11]
Global $ClickedLine=0

Global $GuiSamenvatting = GUICreate("Gui", 350, 450)

$idListview = GUICtrlCreateListView("#  | FILES  | PROJECTCODE  ", 10, 10, 300, 400) ;,$LVS_SORTDESCENDING)
For $n = 1 To 10 ;
   $FileArray[$n] = "Item " & $n
    $CodeArray[$n] =  $n
    GUICtrlCreateListViewItem($n & "|" & $FileArray [$n] & "|" & $CodeArray [$n] , $idListview)
Next


GUISetState(@SW_SHOW)

Global $aLV_Content = _GUIListViewEx_ReadToArray($idListview)
Global $iLV_Index = _GUIListViewEx_Init($idListview, $aLV_Content, 0, 0, True, 32)
_GUIListViewEx_SetEditStatus($iLV_Index, "2") ; Project column editable maken
_GUIListViewEx_MsgRegister()
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')

; Loop until the user exits.
Do
    Local $ArrayMetItemsListView = _GUIListViewEx_EventMonitor() ; Allow the UDF to monitor events



    If Not @error Then ; There was no error detected

        Switch @extended
            Case 1 ; Standard edit mode
                If $ArrayMetItemsListView <> "" Then ; If edit not aborted
                    If $ArrayMetItemsListView[1][1] = 2 Then
                        Local $IngevoerdeCode = $ArrayMetItemsListView[1][3]
                        Local $AangepasteLijn = $ArrayMetItemsListView[1][0] + 1

                        ;$arr_gevondenprojectcode[$AangepasteLijn]= $IngevoerdeCode

                        GUISetState(@SW_HIDE, $GuiSamenvatting)
                        GUIDelete($GuiSamenvatting)
                        ;MaakGuiSamenvatting ()
                    EndIf
                Else
                  if $ClickedLine <> 0 Then
                  MsgBox($MB_OK,"Linenumber Message", "Linenumber: " & $ClickedLine )
                  $clickedLine = 0
               EndIf
               EndIf
         EndSwitch



    EndIf



Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $tNMHDR = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom')
    Local $Index = DllStructGetData($tNMHDR, 'Index')
    Local $Code = DllStructGetData($tNMHDR, 'Code')

    Switch $IDFrom
        Case $idListview
            Switch $Code
            Case $LVN_ITEMCHANGED
                $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
                ; if state has changed
                If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _
                    DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then
                    ; take care of only newly selected items (not deselected ones)
                    If BitAND(DllStructGetData($NMLISTVIEW, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED  Then
                        $Item = _GUICtrlListView_GetItem($idListview, $Index)
                        $ClickedLine = $Index + 1
                        ConsoleWrite("You clicked line number: " & $ClickedLine & @CR)

                    EndIf
                EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Link to comment
Share on other sites

  • Moderators

Martino,

Quote

Strange that it's so hard to catch a click or a double click on a listitem.

Blame Windows, not AutoIt, - and that is one of the reasons why I wrote my UDF.

Quote

I read about _GUIListViewEx_SetEditStatus with $iMode = 9 but I find it hard to understand.

It is actually very simple - as this example shows:

#include <GUIConstantsEx.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

#include "GUIListViewEx.au3"

; Place the required folder path here
$sPath = @ScriptDir & "\"
; List all files in the folder
$aList = _FileListToArray($sPath, "*.*",$FLTA_FILES)

$hGUI = GUICreate("Test", 500, 500)

$cLV = GUICtrlCreateListView("Files", 10, 30, 300, 300, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS))
_GUICtrlListView_SetExtendedListViewStyle($cLV, $LVS_EX_FULLROWSELECT)

_GUICtrlListView_SetColumnWidth($cLV, 0, 270)

; Fill the ListView with the filenames
For $i = 1 To $aList[0]
    GUICtrlCreateListViewItem($aList[$i], $cLV)
Next

; Initialise the ListView within the UDF
$aLVArray =_GUIListViewEx_ReadToArray($cLV)
$iLVIndex = _GUIListViewEx_Init($cLV, $aLVArray)
; Set the action on double-click to run a user function
_GUIListViewEx_SetEditStatus($iLVIndex, 0, 9, _ShowPDF)

_GUIListViewEx_MsgRegister()

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    _GUIListViewEx_EventMonitor()

WEnd

; You need these 4 parameters
Func _ShowPDF($hHandle, $iIndex, $iRow, $iCol)

    ; get the ListView content
    $aLVContent = _GUIListViewEx_ReturnArray($iIndex)
    ; Get the selected file path by reading the returned array
    $sSelFile = $sPath & $aLVContent[$iRow][0]
    ; And here it is - you can now do what you wish with it
    MsgBox($MB_SYSTEMMODAL, "Selected file", $sSelFile)

EndFunc

As you can see, all you need to do is use _SetEditStatus to define the function to call and the UDF does it all for you.

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

Quote

It is actually very simple - as this example shows:

M23: you made it simple indeed. Perfect example.

 

I was going in the right direction but i was lost in the end. You showed me the light.

i had an error in the custom function

So code below

_GUIListViewEx_SetEditStatus($iLV_Index, 1, 9, _ShowPDF)

in combination with

Func _ShowPDF($hHandle, $iIndex, $iRow, $iCol)

    ; get the ListView content
    $aLVContent = _GUIListViewEx_ReturnArray($iIndex)
    ; Get the selected file path by reading the returned array
    $sSelFile = $sPath & $aLVContent[$iRow][1]
    ; And here it is - you can now do what you wish with it
    ShellExecute ($sSelFile)        ; because i wish to open the pdf                                                            
    WinActivate ("Adobe")

EndFunc

did it.

Thank you again M23.

 

Link to comment
Share on other sites

  • Moderators

Martino,

My pleasure as always.

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