TreeView und editierbare Items.

  • Hallo,
    Ich habe hier mal dieses Hilfebeispiel leicht abgeändert:

    Spoiler anzeigen
    [autoit]

    #include <TreeViewConstants.au3>
    #include <GuiConstantsEx.au3>
    #include <GuiTreeView.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("TreeView Edit Text", 400, 300)
    $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $TVS_EDITLABELS)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Dim $hItem[6]
    For $x = 0 To 5
    $hItem[$x] = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x + 1))
    Next

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg(0x004E, "MY_WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

    [/autoit] [autoit][/autoit] [autoit]

    Func MY_WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    ;~ #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    ;~ ConsoleWrite($hWnd & @TAB & $iMsg & @TAB & $iwParam & @TAB & $ilParam & @TAB & $iIDFrom & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hTreeView
    Switch $iCode
    Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
    _GUICtrlTreeView_EditText($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView))
    ConsoleWrite("Doppelklick" & @CRLF)
    Return 1 ; nonzero to not allow the default processing
    ;~ Return 0 ; zero to allow the default processing
    Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
    ConsoleWrite("Edit angefangen" & @CRLF)
    ;~ Return 1 ; nonzero to not allow the default processing
    Return 0 ; zero to allow the default processing
    Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
    ConsoleWrite("Edit beendet" & @CRLF)
    ;~ Return 1 ; nonzero to not allow the default processing
    Return 0 ; zero to allow the default processing
    EndSwitch
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    Return $GUI_RUNDEFMSG
    EndFunc ;==>MY_WM_NOTIFY

    [/autoit]

    könnt ihr mir sagen, warum
    1. Die Lables nur bei einem "einfachen" klick, wenn das Item schon markiert war, editiert werden,
    2. Die Änderungen nicht übernommen werden?

    Wäre für DescribeIt sehr praktisch - das spart ne Menge platz im GUI, wenn ich die InputBox rausnehme, die ich bisher verwendet hab.

    • Offizieller Beitrag

    Die TreeView-Funktionen sind m.M. noch nicht ausgereift. Das Übernehmen von Änderungen funktioniert ja auch mit dem Original Hilfebsp. nicht wirklich. Egal was ich reinschreibe, es wird nur das erste Zeichen übernommen. ;)
    Ist zwar etwas aufwändiger, aber sicher: Schreibe dein eigenes Edit-Tool, so wie ich es für ListView-Editierung gemacht hatte.

  • Danke, und ich dachte schon es liegt an mir :D

    Ich habe grade ein sehr einfaches Workaround gefunden: nicht perfekt, aber es funktioniert.
    Wenn man jetzt noch die Enter Taste abfangen könnte wär ich zufrieden, aber _GUICtrlTreeView_EndEdit hat leider keinerlei wirkung :(
    Nicht allzu schlimm - sowas kann man später verfeinern.

    Spoiler anzeigen
    [autoit]

    #include <Misc.au3>
    #include <StructureConstants.au3>
    #include <TreeViewConstants.au3>
    #include <GuiConstantsEx.au3>
    #include <GuiTreeView.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("TreeView Edit Text", 400, 300)
    $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $TVS_EDITLABELS)
    $hTreeView = GUICtrlGetHandle($hTreeView)
    Global $hEdit, _ ; Handle to Listview-Edit Control
    $hSel ; Current selected Item

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Dim $hItem[6]
    For $x = 0 To 5
    $hItem[$x] = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x + 1))
    Next

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg(0x004E, "MY_WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

    [/autoit] [autoit][/autoit] [autoit]

    Func MY_WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    ;~ #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    ;~ ConsoleWrite($hWnd & @TAB & $iMsg & @TAB & $iwParam & @TAB & $ilParam & @TAB & $iIDFrom & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hTreeView
    Switch $iCode
    Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
    $hSel = _GUICtrlTreeView_GetSelection($hTreeView)
    _GUICtrlTreeView_EditText($hTreeView, $hSel)
    $hEdit = _GUICtrlTreeView_GetEditControl($hTreeView)
    ConsoleWrite("Doppelklick" & @CRLF)
    AdlibRegister("_GetEditText", 10) ; Funktion per Adlibregister aufrufen, damit erst der DLLCallback zurück gegeben werden kann
    Return 1 ; nonzero to not allow the default processing
    ;~ Return 0 ; zero to allow the default processing
    EndSwitch
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    Return $GUI_RUNDEFMSG
    EndFunc ;==>MY_WM_NOTIFY

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetEditText()
    Local $sRet, $sBuffer
    AdlibUnRegister("_GetEditText")
    Do
    $sBuffer = $sRet
    $sRet = ControlGetText($hTreeView, "", $hEdit)
    Until $sRet = "" Or _IsPressed("0D")
    _GUICtrlTreeView_EndEdit($hEdit)
    _GUICtrlTreeView_SetText($hTreeView, $hSel, $sBuffer)
    ConsoleWrite($sBuffer & @CRLF)
    EndFunc ;==>_GetEditText

    [/autoit] [autoit][/autoit] [autoit][/autoit]
    • Offizieller Beitrag

    So funktioniert Dein Beispiel von oben:

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <GuiTreeView.au3>
    #include <StructureConstants.au3>
    #include <TreeViewConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("TreeView Edit Text", 400, 300)
    $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, BitOr($GUI_SS_DEFAULT_TREEVIEW, $TVS_EDITLABELS))
    $hWndTreeView = GUICtrlGetHandle($hTreeView) ; <-- das ist wichtig! Die UDFs am besten immer mit dem Handle aufrufen.
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Dim $hItem[6], $iEditItem
    For $x = 0 To 5
    $hItem[$x] = _GUICtrlTreeView_Add($hWndTreeView, 0, StringFormat("[%02d] New Item", $x + 1))
    Next

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg(0x004E, "MY_WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

    [/autoit] [autoit][/autoit] [autoit]

    Func MY_WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    ;~ #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    ;~ ConsoleWrite($hWnd & @TAB & $iMsg & @TAB & $iwParam & @TAB & $ilParam & @TAB & $iIDFrom & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndTreeView
    Switch $iCode
    Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
    $iEditItem = _GUICtrlTreeView_GetEditControl($hWndTreeView)
    _GUICtrlTreeView_EditText($hWndTreeView, $iEditItem)
    ConsoleWrite("Doppelklick" & @CRLF)
    Return 1 ; nonzero to not allow the default processing
    ;~ Return 0 ; zero to allow the default processing
    Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
    ConsoleWrite("Edit angefangen" & @CRLF)
    ;~ Return 1 ; nonzero to not allow the default processing
    Return 0 ; zero to allow the default processing
    Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
    ConsoleWrite("Edit beendet" & @CRLF)
    _GUICtrlTreeView_EndEdit($hWndTreeView)
    Return 1 ; zero to allow the default processing
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>MY_WM_NOTIFY

    [/autoit]
  • Nicht ganz - es wird immer das erste geändert.
    Mit einer kleinen Anpassung:

    [autoit]


    Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
    $iEditItem = _GUICtrlTreeView_GetEditControl($hWndTreeView)
    _GUICtrlTreeView_EditText($hWndTreeView, $iEditItem)
    ;zu
    Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
    _GUICtrlTreeView_EditText($hWndTreeView, _GUICtrlTreeView_GetSelection($hWndTreeView))

    [/autoit]

    Funktinoiert es. Leider nur genauso gut wie mein workaround - denn mit Enter kann ich den Text immer noch nicht abschicken :S

    • Offizieller Beitrag

    Upps, da war noch ein kleiner Fehler. So geht's:

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <GuiTreeView.au3>
    #include <Misc.au3>
    #include <StructureConstants.au3>
    #include <TreeViewConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUICreate("TreeView Edit Text", 400, 300)
    $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, BitOr($GUI_SS_DEFAULT_TREEVIEW, $TVS_EDITLABELS))
    $hWndTreeView = GUICtrlGetHandle($hTreeView) ; <-- das ist wichtig! Die UDFs am besten immer mit dem Handle aufrufen.
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Dim $hItem[6], $iEditItem
    For $x = 0 To 5
    $hItem[$x] = _GUICtrlTreeView_Add($hWndTreeView, 0, StringFormat("[%02d] New Item", $x + 1))
    Next

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg(0x004E, "MY_WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    Do
    If _IsPressed("0D") Then _GUICtrlTreeView_EndEdit($hWndTreeView) ; <-- zum beenden des Editierens mit [Enter]
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

    [/autoit] [autoit][/autoit] [autoit]

    Func MY_WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    ;~ #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    ;~ ConsoleWrite($hWnd & @TAB & $iMsg & @TAB & $iwParam & @TAB & $ilParam & @TAB & $iIDFrom & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndTreeView
    Switch $iCode
    Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
    ConsoleWrite("Doppelklick" & @CRLF)
    Return 1 ; nonzero to not allow the default processing
    ;~ Return 0 ; zero to allow the default processing
    Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
    $iEditItem = _GUICtrlTreeView_GetEditControl($hWndTreeView) ; <-- das muss natürlich hier hin, nicht bei Doppelklick
    _GUICtrlTreeView_EditText($hWndTreeView, $iEditItem)
    ConsoleWrite("Edit angefangen" & @CRLF)
    ;~ Return 1 ; nonzero to not allow the default processing
    Return 0 ; zero to allow the default processing
    Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
    ConsoleWrite("Edit beendet" & @CRLF)
    _GUICtrlTreeView_EndEdit($hWndTreeView)
    Return 1 ; zero to allow the default processing
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>MY_WM_NOTIFY

    [/autoit]
  • Womit wir wieder beim "erst makieren, dann einzelnd klicken um zu editieren"-Problem wären.
    Ich benutzt jetzt einfach DIESE Version, da klappt alles so wie ich es will. Danke:)

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <GuiTreeView.au3>
    #include <Misc.au3>
    #include <StructureConstants.au3>
    #include <TreeViewConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUICreate("TreeView Edit Text", 400, 300)
    $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_EDITLABELS))
    $hWndTreeView = GUICtrlGetHandle($hTreeView) ; <-- das ist wichtig! Die UDFs am besten immer mit dem Handle aufrufen.
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Dim $hItem[6], $iEditItem
    For $x = 0 To 5
    $hItem[$x] = _GUICtrlTreeView_Add($hWndTreeView, 0, StringFormat("[%02d] New Item", $x + 1))
    Next

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg(0x004E, "MY_WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    ; Loop until user exits
    Do
    If _IsPressed("0D") Then _GUICtrlTreeView_EndEdit($hWndTreeView) ; <-- zum beenden des Editierens mit [Enter]
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

    [/autoit] [autoit][/autoit] [autoit]

    Func MY_WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndTreeView
    Switch $iCode
    Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
    ConsoleWrite("Doppelklick" & @CRLF)
    _GUICtrlTreeView_EditText($hWndTreeView, _GUICtrlTreeView_GetSelection($hWndTreeView)) ; <- Edit des gewählten elements starten!
    $iEditItem = _GUICtrlTreeView_GetEditControl($hWndTreeView) ; <- Edit handle auslesen
    Return 1 ; nonzero to not allow the default processing
    ;~ Return 0 ; zero to allow the default processing
    Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
    ConsoleWrite("Edit beendet" & @CRLF)
    _GUICtrlTreeView_EndEdit($hWndTreeView)
    Return 1 ; zero to allow the default processing
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>MY_WM_NOTIFY

    [/autoit]