Sign in to follow this  
Followers 0
ReFran

TreeView - editable?

4 posts in this topic

#1 ·  Posted (edited)

Hi,

I work on GUI for PDF handling. For to set up the bookmarks I work with a TreeView. Reading in the bookmarks from a PDF works good and looks good in the TreeView. Now, for writing, it would be fine if the bookmarks would be editable direct in the treeview.

I saw an example how to edit an ListView. But I didn't find anything find for TreeView.

Is that not possible? Any workaround?

Best regards, Reinhard

Edited by ReFran

Share this post


Link to post
Share on other sites



some constants needed

Global Const $TV_FIRST = 0x1100

Global Const $TVS_EDITLABELS = 0x8

Global Const $TVGN_CARET = 0x9

Global Const $TVM_GETNEXTITEM = ($TV_FIRST + 10)

Global Const $TVM_EDITLABELA = ($TV_FIRST + 14)

Global Const $TVM_ENDEDITLABELNOW = ($TV_FIRST + 22)

Start the edit

$h_item = GUICtrlSendMsg($treeview, $TVM_GETNEXTITEM, $TVGN_CARET, 0)

GUICtrlSendMsg($treeview, $TVM_EDITLABELA,0,$h_item)

the edit control is the same as ListView "Edit1"

Cancel Edit

GUICtrlSendMsg($treeview,$TVM_ENDEDITLABELNOW,True,0)

I think you can probably figure out how to update based on what was done for the ListView

Gary


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Edit: check scripts and scraps

here's a quick modification to the example from the help file

selet about under general, type in new text and press enter

#include <GUIConstants.au3>
Global Const $TV_FIRST = 0x1100
Global Const $TVS_EDITLABELS = 0x8
Global Const $TVGN_CARET = 0x9
Global Const $TVM_GETNEXTITEM = ($TV_FIRST + 10)
Global Const $TVM_EDITLABELA = ($TV_FIRST + 14)
Global Const $TVM_ENDEDITLABELNOW = ($TV_FIRST + 22)


$GUI = GUICreate("My GUI with treeview", 350, 212)

$treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_EDITLABELS), $WS_EX_CLIENTEDGE)
$generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
$displayitem = GUICtrlCreateTreeViewItem("Display", $treeview)
$aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem)
$compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem)
$useritem = GUICtrlCreateTreeViewItem("User", $generalitem)
$resitem = GUICtrlCreateTreeViewItem("Resolution", $displayitem)
$otheritem = GUICtrlCreateTreeViewItem("Other", $displayitem)

$startlabel = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20)
$aboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
GUICtrlSetState(-1, $GUI_HIDE); Hides the "aboutlabel"-text during initialization
$compinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
GUICtrlSetState(-1, $GUI_HIDE); Hides the "compinfo"-text during initialization

$okbutton = GUICtrlCreateButton("OK", 100, 185, 70, 20)
$cancelbutton = GUICtrlCreateButton("Cancel", 180, 185, 70, 20)

GUISetState()
$dll = DllOpen("user32.dll")
While 1
    $msg = GUIGetMsg()
    Local $pressed = _IsPressedMod($dll)
    If $pressed = 27 And ControlCommand($GUI, "", "Edit1", "IsVisible", "") Then _Cancel(); pressed esc
    If $pressed = 13 And ControlCommand($GUI, "", "Edit1", "IsVisible", "") Then _Rename(); pressed enter
    Select
        Case $msg = $cancelbutton Or $msg = $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $msg = $okbutton
            $item = GUICtrlRead($treeview)    ; Get the controlID of the current selected treeview item
            If $item = 0 Then
                MsgBox(64, "TreeView Demo", "No item currently selected")
            Else
                $advmsg = GUICtrlRead($item, 1); Get advanced infos about the treeview item
                If ($advmsg[0] == 0) Then
                    MsgBox(16, "Error", "Error while retrieving infos about item")
                Else
                    MsgBox(64, "TreeView Demo", "Current item selected is: " & $advmsg[0]); $advmsg[0] contains the text and $advmsg[1] the state value of the treeview item
                EndIf
            EndIf
        ; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter)
        Case $msg = $generalitem
            GUIChangeItems($aboutlabel, $compinfo, $startlabel, $startlabel)
            
        Case $msg = $aboutitem
            GUICtrlSetState($compinfo, $GUI_HIDE)
            GUIChangeItems($startlabel, $startlabel, $aboutlabel, $aboutlabel)
            $h_item = GUICtrlSendMsg($treeview, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
            GUICtrlSendMsg($treeview, $TVM_EDITLABELA, 0, $h_item)
            HotKeySet("{Enter}", "_Rename")
            HotKeySet("{Esc}", "_Cancel")
            
        Case $msg = $compitem
            GUIChangeItems($startlabel, $aboutlabel, $compinfo, $compinfo)
    EndSelect
WEnd
DllClose($dll)

GUIDelete()

Exit

Func GUIChangeItems($hidestart, $hideend, $showstart, $showend)
    Local $idx
    
    For $idx = $hidestart To $hideend
        GUICtrlSetState($idx, $GUI_HIDE)
    Next
    For $idx = $showstart To $showend
        GUICtrlSetState($idx, $GUI_SHOW)
    Next
EndFunc  ;==>GUIChangeItems

Func _Rename()
    Local $newText = ControlGetText($GUI, "", "Edit1")
    Local $item = GUICtrlRead($treeview)
    ConsoleWrite($item & @LF)
    GUICtrlSetData($item, $newText)
    HotKeySet("{Enter}")
    HotKeySet("{Esc}")
    GUICtrlSendMsg($treeview, $TVM_ENDEDITLABELNOW, False, 0)
EndFunc  ;==>_Rename

Func _Cancel()
    GUICtrlSendMsg($treeview, $TVM_ENDEDITLABELNOW, True, 0)
    HotKeySet("{Enter}")
    HotKeySet("{Esc}")
EndFunc  ;==>_Cancel

Func _IsPressedMod($dll = "user32.dll")
    Local $aR, $bRv, $hexKey, $i
    For $i = 8 To 128
        $hexKey = '0x' & Hex($i, 2)
        $aR = DllCall($dll, "int", "GetAsyncKeyState", "int", $hexKey)
        If $aR[0] <> 0 Then Return $i
    Next
    Return 0
EndFunc  ;==>_IsPressedMod
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Hi Gary.

I don't now what I should write. It works GREAT!.

After some searching I though already I would have to use for the bookmark part a third party freeware. But with your example I can write it by myself in the way I like it.

Sometimes I should try to understand, where the "Const" come from and the use of it. I didn't find "$TVS_EDITLABELS". But at time I'm simply very happy that I've a solution.

Thanks for it, Reinhard

Share this post


Link to post
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
Sign in to follow this  
Followers 0