Treeview Problem

  • Hallo,

    ich habe einen Treeview erstellt, welches 5 Items und jeweils 5 Subitems hat.

    Also so:

    +-Item1
    ----Subitem1
    ----Subitem2
    ----Subitem3
    ----Subitem4
    ----Subitem5

    +-Item2
    ----Subitem1
    ----Subitem2
    ----Subitem3
    ----Subitem4
    ----Subitem5

    usw.

    Wie kann ich nun von einem ausgewähltem Subitem den Text inklusive des Items herauslesen?
    So sollte das ungefähr aussehen: Item1/Subitem3.

    • Offizieller Beitrag

    Hier, schau mal in dem Bsp. die Func click_TV() an.

    Spoiler anzeigen
    [autoit]

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

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

    Opt("MustDeclareVars", 1)
    Opt("GuiOnEventMode", 1)

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

    Global $gui, $hImage, $hTV, $aID_Sub[5], $ID_Table, $item

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

    $gui = GUICreate('Test TreeView')
    GUISetOnEvent($GUI_EVENT_CLOSE, '_end')
    $hTV = GUICtrlCreateTreeView(10,10,300,350,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, _
    $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    Global $WM_NOTIFY_DUMMY = GUICtrlCreateDummy()
    GUICtrlSetOnEvent($WM_NOTIFY_DUMMY,"click_TV")

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

    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 98)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 96)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 36)
    _GUICtrlTreeView_SetNormalImageList($hTV, $hImage)

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

    _GUICtrlTreeView_BeginUpdate($hTV)
    $ID_Table = _GUICtrlTreeView_Add($hTV, 0, 'Table', 0, 0)
    For $i = 1 To 5
    $aID_Sub[$i-1] = _GUICtrlTreeView_AddChild($hTV, $ID_Table, 'Sub' & $i, 1, 1)
    For $j = 1 To 3
    $item = _GUICtrlTreeView_AddChild($hTV, $aID_Sub[$i-1], 'Sub_Sub' & $j, 2, 2)
    Next
    Next
    _GUICtrlTreeView_EndUpdate($hTV)
    _GUICtrlTreeView_Expand($hTV, $ID_Table)

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

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

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

    While 1
    Sleep(100)
    WEnd

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

    Func _end()
    Exit
    EndFunc

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

    Func click_TV()
    Local $hTVItem = _GUICtrlTreeView_GetSelection($hTV)
    WinSetTitle($gui, '', _GUICtrlTreeView_GetText($hTV,$hTVItem))
    EndFunc

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

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTV
    If Not IsHWnd($hTV) Then $hWndTreeview = GUICtrlGetHandle($hTV)

    [/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_CLICK
    GUICtrlSendToDummy($WM_NOTIFY_DUMMY)
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]

    Edit:
    Um das Parent mit auszugeben, ändere die Funktion so ab:

    [autoit]

    Func click_TV()
    Local $hTVItem = _GUICtrlTreeView_GetSelection($hTV)
    Local $hParent = _GUICtrlTreeView_GetParentHandle($hTV, $hTVItem)
    Local $title = ''
    If $hParent Then $title = _GUICtrlTreeView_GetText($hTV,$hParent) & ' / '
    WinSetTitle($gui, '', $title & _GUICtrlTreeView_GetText($hTV,$hTVItem))
    EndFunc

    [/autoit]
    • Offizieller Beitrag

    Schau dir mal _GUICtrlListView_Scroll an.