Sign in to follow this  
Followers 0
danielkza

Tree View with Editable Labels

6 posts in this topic

I want to make a treeview with editable labels,but i have no idea how to get wich control was being edited or how to get the new text in TVN_BEGINLABELEDIT or TVN_ENDLABELEDIT.

I took a look at the example from Siao at http://www.autoitscript.com/forum/index.php?showtopic=56411 but i didn't understand any of it.

Can anybody help me?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi! Try this:

#include <GuiConstants.au3>
#include <GuiTreeView.au3>

$hGUI = GUICreate("Test GUI", 300, 200)

$hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 280, 180, _
BitOR($TVS_EDITLABELS, $TVS_INFOTIP, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_HASBUTTONS), $WS_EX_CLIENTEDGE)

For $i = 1 To 5
    $hItem = _GUICtrlTreeView_Add($hTreeView, $i, "Item" & $i)
    For $j = 1 To 5
        _GUICtrlTreeView_AddChild($hTreeView, $hItem, "SubItem" & $j)
    Next
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $HwndFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $HwndFrom = DllStructGetData($tNMHDR, "HwndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $HwndFrom
        Case $hTreeView
            Switch $iCode
                Case $TVN_BEGINLABELEDIT
                    Return False
                Case $TVN_ENDLABELEDIT
                    Local $tInfo = DllStructCreate($tagNMTVDISPINFO, $lParam)
                    Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _
                                                     DllStructGetData($tInfo, "Text"))
                    If StringLen(DllStructGetData($tBuffer, "Text")) Then Return 1
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
:) Edited by rasim

Share this post


Link to post
Share on other sites

Hi! Try this:

#include <GuiConstants.au3>
#include <GuiTreeView.au3>

$hGUI = GUICreate("Test GUI", 300, 200)

$hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 280, 180, _
BitOR($TVS_EDITLABELS, $TVS_INFOTIP, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_HASBUTTONS), $WS_EX_CLIENTEDGE)

For $i = 1 To 5
    $hItem = _GUICtrlTreeView_Add($hTreeView, $i, "Item" & $i)
    For $j = 1 To 5
        _GUICtrlTreeView_AddChild($hTreeView, $hItem, "SubItem" & $j)
    Next
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $HwndFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $HwndFrom = DllStructGetData($tNMHDR, "HwndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $HwndFrom
        Case $hTreeView
            Switch $iCode
                Case $TVN_BEGINLABELEDIT
                    Return False
                Case $TVN_ENDLABELEDIT
                    Local $tInfo = DllStructCreate($tagNMTVDISPINFO, $lParam)
                    Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", _
                                                     DllStructGetData($tInfo, "Text"))
                    If StringLen(DllStructGetData($tBuffer, "Text")) Then Return 1
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFuncoÝ÷ Ûú®¢×è®Ø^r^nëb¦ÞjènW¦Z§Úò¶®¶­sdFÆÅ7G'V7DvWDFFb33c·D'VffW"ÂgV÷CµFWBgV÷C²
i only get the first letter of the new string.

Does anyone know what's the problem?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Does anyone know what's the problem?

The above example is made for ansi only, and you're most likely trying to make it work with unicode treeview (which is what it is if you're running unicode version of AutoIt and use native GuiCtrl... functions to create treeview and its items).

To work for both unicode and ansi, the switch statement in the above example should look like this:

Switch $HwndFrom
        Case $hTreeView
            Switch $iCode
                Case $TVN_BEGINLABELEDIT, $TVN_BEGINLABELEDITW
                    Return False
                Case $TVN_ENDLABELEDIT, $TVN_ENDLABELEDITW
                    Local $tInfo = DllStructCreate($tagNMTVDISPINFO, $lParam), $sBuffer = "wchar Text[" & DllStructGetData($tInfo, "TextMax") & "]", $tBuffer, $sText
                    If Not _GUICtrlTreeView_GetUnicodeFormat($HwndFrom) Then $sBuffer = StringTrimLeft($sBuffer, 1)
                    $tBuffer = DllStructCreate($sBuffer, DllStructGetData($tInfo, "Text"))
                    $sText = DllStructGetData($tBuffer, "Text")
;~                  ConsoleWrite($sText & @CRLF)
                    If StringLen($sText) Then Return 1
            EndSwitch
    EndSwitch
Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

To work for both unicode and ansi, the switch statement in the above example should look like this:

I did not know this. Thank you! :)

Share this post


Link to post
Share on other sites

The above example is made for ansi only, and you're most likely trying to make it work with unicode treeview (which is what it is if you're running unicode version of AutoIt and use native GuiCtrl... functions to create treeview and its items).

To work for both unicode and ansi, the switch statement in the above example should look like this:

Switch $HwndFrom
        Case $hTreeView
            Switch $iCode
                Case $TVN_BEGINLABELEDIT, $TVN_BEGINLABELEDITW
                    Return False
                Case $TVN_ENDLABELEDIT, $TVN_ENDLABELEDITW
                    Local $tInfo = DllStructCreate($tagNMTVDISPINFO, $lParam), $sBuffer = "wchar Text[" & DllStructGetData($tInfo, "TextMax") & "]", $tBuffer, $sText
                    If Not _GUICtrlTreeView_GetUnicodeFormat($HwndFrom) Then $sBuffer = StringTrimLeft($sBuffer, 1)
                    $tBuffer = DllStructCreate($sBuffer, DllStructGetData($tInfo, "Text"))
                    $sText = DllStructGetData($tBuffer, "Text")
;~                  ConsoleWrite($sText & @CRLF)
                    If StringLen($sText) Then Return 1
            EndSwitch
    EndSwitch
Thanks,that solved the problem,i'd never think of something like that!

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