Jump to content

edit ListView sub-items


Go to solution Solved by Nine,

Recommended Posts

Posted

Hello, first of all, greetings and I hope you are well.

I hope you can help me. I need to know how to edit columns 1 and 2.

How to double click on either column 1 or 2 and change the name, then save the changes by pressing enter

Column 0 is the numbers. Column 1 is the program name. Column 2 is the program path.

This is my code so far

 

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>



#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>


#include <MsgBoxConstants.au3>


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


#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#Include <WinAPI.au3>

#include <TabConstants.au3>

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>




$hGUI = GUICreate("Test", 1024, 768)



$hListView = GUICtrlCreateListView("#|Program name|Program path", 10, 10, 1000, 150,BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))

_GuiCtrlListView_SetColumnWidth($hListView,0,35)
_GuiCtrlListView_SetColumnWidth($hListView,1,200)
_GuiCtrlListView_SetColumnWidth($hListView,2,450)




 Local $iRead = FileRead(@ScriptDir & "\test.ini")
    Local $iRead2 = FileRead(@ScriptDir & "\test2.ini")
    Local $aString = StringSplit(StringStripCR($iRead), @LF)
    Local $aString1 = StringSplit(StringStripCR($iRead2), @LF)

    For $i = 1 To $aString[0]
        If $aString[$i] = "" Then ContinueLoop
        For $i = 1 To $aString1[0]
        If $aString1[$i] = "" Then ContinueLoop

        GUICtrlCreateListViewItem($i & "|" & StringRegExpReplace($aString[$i], "^.*\\", "") & "|" &  StringRegExpReplace($aString1[$i], "(^.*\).*", "\1"), $hListView)


        Next
        Next




$OkButton = GUICtrlCreateButton("Ok", 50, 170, 75, 23)

$AddButton = GUICtrlCreateButton("Add new path", 130, 170, 75, 23)

$RemButton = GUICtrlCreateButton("Remove", 210, 170, 75, 23)

$Buttonname = GUICtrlCreateButton("search", 342, 249, 75, 23)

$inputname = GUICtrlCreateInput("", 50, 250, 280, 20)


$AddGUI = GUICreate("Add new path", 300, 100, -1, -1, -1, -1, $hGUI)

$input = GUICtrlCreateInput("", 10, 20, 280, 20)

$Browse_Button = GUICtrlCreateButton("Browse exe files", 10, 60, 85, 23)

$AddStr_Button = GUICtrlCreateButton("OK", 130, 60, 75, 23)

$Close_Button = GUICtrlCreateButton("Close", 215, 60, 75, 23)

GUISetState(@SW_SHOW, $hGUI)






While 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case $GUI_EVENT_CLOSE, $Close_Button
            If $msg[1] = $hGUI Then
                Exit
            Else
                GUISetState(@SW_ENABLE, $hGUI)
                GUISetState(@SW_HIDE, $AddGUI)
            EndIf


        Case $Buttonname


            Local $sFile  = GUICtrlRead($inputname)

            _GUICtrlListView_SetItemSelected($hListView, -1,False,False)
                ; Get the text from the Input control
                Local $sSearchText = GUICtrlRead($inputname)
                ;Local $sSearchText = "Another Target"
                Local $iColumnToSearch = 1


                For $i = 0 To _GUICtrlListView_GetItemCount($hListView) - 1
                If _GUICtrlListView_GetItemText($hListView, $i,$iColumnToSearch) = $sSearchText Then

                    GUICtrlSetState($hListView, $GUI_FOCUS)
                   _GUICtrlListView_SetItemSelected($hListView, $i, True,True)


        EndIf
    Next




        Case $OkButton
            $sData = ""
            $sData2 = ""

            For $i = 0 To _GUICtrlListView_GetItemCount($hListView) - 1
                $sData &= _GUICtrlListView_GetItemText($hListView, $i, 1)  & @CRLF
                $sData2 &= _GUICtrlListView_GetItemText($hListView, $i, 2) & @CRLF

            Next

            $hFile = FileOpen(@ScriptDir & "\test.ini", 2)
            FileWrite($hFile, $sData)
            $hFile = FileOpen(@ScriptDir & "\test2.ini", 2)
            FileWrite($hFile, $sData2)
            FileClose($hFile)
            Exit


        Case $AddButton
            GUICtrlSetData($input, "")

            GUISetState(@SW_DISABLE, $hGUI)
            GUISetState(@SW_SHOW, $AddGUI)
        Case $RemButton
            _GUICtrlListView_DeleteItemsSelected($hListView)
        Case $Browse_Button
            $sFile = FileOpenDialog(@SCRIPTNAME,@WORKINGDIR,"(*.exe;*.bat)", 1, "", $AddGUI)




            If $sFile = "" Then ContinueCase

            GUICtrlSetData($input, $sFile)
        Case $AddStr_Button
            $sString = GUICtrlRead($input)
            If $sString = "" Then ContinueCase

            $sFile = StringRegExpReplace($sString, "^.*\\", "")
            $sPath = StringRegExpReplace($sString, "(^.*\).*", "\1")

            GUICtrlCreateListViewItem(_GUICtrlListView_GetItemCount($hListView) + 1 & "|" & $sFile & "|" & $sPath, $hListView)

            GUISetState(@SW_ENABLE, $hGUI)
            GUISetState(@SW_HIDE, $AddGUI)
    EndSwitch
WEnd

I will appreciate your help

  • Solution
Posted (edited)

You can't, not with standard functionality of a list view .  Only the item (first column) can be edited in place using $LVS_EDITLABELS.

If you truly want it,  you would need a workaround, like creating an input box when you dbl-click on a subitem.

Here a simple example :

#include <GUIConstants.au3>
#include <GuiListView.au3>

Opt("GUICloseOnESC", 0)
Opt("MustDeclareVars", True)

Global $hList, $idDummy

Example()

Func Example()
  Local $hMain = GUICreate("Example", 230, 170)

  Local $idList = GUICtrlCreateListView("Column 1|Column 2", 10, 10)
  GUICtrlCreateListViewItem("Item 1|Item 2", $idList)
  GUICtrlCreateListViewItem("Item 3|Item 4", $idList)
  $hList = GUICtrlGetHandle($idList)
  $idDummy = GUICtrlCreateDummy()

  GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)
  GUISetState()

  Local $iItem, $iSubItem, $aRect, $sData, $aPos = ControlGetPos($hMain, "", $idList)

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $idDummy
        $iItem = _WinAPI_LoWord(GUICtrlRead($idDummy))
        $iSubItem = _WinAPI_HiWord(GUICtrlRead($idDummy))
        If $iSubItem = 0 Then ContinueLoop
        $aRect = _GUICtrlListView_GetSubItemRect($idList, $iItem, $iSubItem)
        $sData = GUICreateInput($hMain, _GUICtrlListView_GetItemText($idList, $iItem, $iSubItem), $aRect[0] + $aPos[0], $aRect[1] + $aPos[1], $aRect[2] - $aRect[0], $aRect[3] - $aRect[1])
        If $sData Then _GUICtrlListView_SetItemText($idList, $iItem, $sData, $iSubItem)
    EndSwitch
  WEnd
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
  If $tInfo.hWndFrom = $hList And $tInfo.Code = $NM_DBLCLK Then GUICtrlSendToDummy($idDummy, _WinAPI_MakeLong($tInfo.Index, $tInfo.SubItem))
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func GUICreateInput($hWnd, $sText, $iLeft, $iTop, $iWidth, $iHeight)
  Local $hGUI = GUICreate("", $iWidth, $iHeight, $iLeft, $iTop + 1, $WS_POPUP, $WS_EX_MDICHILD, $hWnd)
  Local $idInput = GUICtrlCreateInput($sText, 0, 1, $iWidth, $iHeight - 1)
  Local $idOut = GUICtrlCreateDummy()
  GUISetState()
  GUISetState(@SW_DISABLE, $hWnd)
  Local $aAccel[2][2] = [["{ENTER}", $idInput], ["{ESC}", $idOut]], $sInput

  GUISetAccelerators($aAccel, $hGUI)
  While True
    Switch GUIGetMsg()
      Case $idInput
        $sInput = GUICtrlRead($idInput)
        ExitLoop
      Case $idOut
        ExitLoop
    EndSwitch
  WEnd
  GUIDelete($hGUI)
  GUISetState(@SW_ENABLE, $hWnd)
  GUISetState(@SW_RESTORE, $hWnd)
  Return $sInput
EndFunc   ;==>GUICreateInput

 

Edited by Nine
better code
Posted

Sorry for the delay, I was working.
Thank you so much for your great help and your time. It's worked like a charm.
I implement it in my GUI and it worked.
¿With all due respect can I tell you nine ?

an apology, my English isn't very good.

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