Jump to content

TreeView


Tiger
 Share

Recommended Posts

How can i get the name of the treeview item. Then I click on the treeviewitem 2.1 then i will show the name in a msgbox

Opt("GUIOnEventMode", 1)
#include <GUIConstants.au3>
Dim $treeviewitem[3]
GUICreate("", 400, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "_close")
$treeview = GUICtrlCreateTreeView(20, 20, 200, 200)
$treeviewitem[1] = GUICtrlCreateTreeViewItem("Tree 1", $treeview)
$treeviewitem[2] = GUICtrlCreateTreeViewItem("Tree 2", $treeview)
GUISetState(@SW_SHOW)
GUICtrlCreateTreeViewItem("Treeitem 1.1", $treeviewitem[1])
GUICtrlCreateTreeViewItem("Treeitem 1.2", $treeviewitem[1])
GUICtrlCreateTreeViewItem("Treeitem 2.1", $treeviewitem[2])
GUICtrlCreateTreeViewItem("Treeitem 2.2", $treeviewitem[2])
Func _close()
    Exit
EndFunc
While 1 
    sleep(500)
WEnd
Edited by Tiger
My UDFs:- _RegEnumKey
Link to comment
Share on other sites

Use latest beta 3.2.9.3

#include <GUIConstants.au3>

Dim $treeviewitem[3]

$gui = GUICreate("", 400, 400)
$treeview = GUICtrlCreateTreeView(20, 20, 200, 200)
$treeviewitem[1] = GUICtrlCreateTreeViewItem("Tree 1", $treeview)
$treeviewitem[2] = GUICtrlCreateTreeViewItem("Tree 2", $treeview)
GUICtrlCreateTreeViewItem("Treeitem 1.1", $treeviewitem[1])
GUICtrlCreateTreeViewItem("Treeitem 1.2", $treeviewitem[1])
GUICtrlCreateTreeViewItem("Treeitem 2.1", $treeviewitem[2])
GUICtrlCreateTreeViewItem("Treeitem 2.2", $treeviewitem[2])
GUISetState(@SW_SHOW)

While 1 
  $msg = GuiGetMsg()
  Select
    Case $msg = $GUI_EVENT_CLOSE
      Exit
    Case $msg = $treeview 
      $item = ControlTreeView($gui, "", $treeview, "GetSelected")
      $text = ControlTreeView($gui, "", $treeview, "GetText", $item)
      MsgBox(0, 'Text',$text)
  EndSelect
WEnd
Edited by Zedna
Link to comment
Share on other sites

Hi guys is possible somehow to add icon on treeview like in listview?

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

Hi guys is possible somehow to add icon on treeview like in listview?

_GUICtrlTreeView_InsertItem

_GUICtrlTreeView_SetIcon

_GUICtrlTreeView_Add

_GUICtrlTreeView_AddChild

_GUICtrlTreeView_AddChildFirst

_GUICtrlTreeView_AddFirst

and probably more in the beta

SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Link to comment
Share on other sites

Looks like it's time for me to move onto beta autoit from what Gary posted above :)

No api calls or beta or anything fancy .. but icons and retrieve the text of the selected item in the crude example below..

#include <GUIConstants.au3>
#include <File.au3>

Opt("GUIOnEventMode", 1)

$Gui = GUICreate("TreeView", 400, 400)
$treeview = GUICtrlCreateTreeView(20, 20, 200, 200)
Root($treeview)
GUISetOnEvent($GUI_EVENT_CLOSE, "_close")
GUISetState(@SW_SHOW)

While 1
    Sleep(500)
WEnd

Func TellMe()
    MsgBox(0,'', GUICtrlRead(@GUI_CtrlId, 1))
EndFunc

Func Root($tvcID)
    Dim $DGD = DriveGetDrive("ALL")
    For $i = 1 To $DGD[0]
        GUICtrlCreateTreeViewItem("(" & $DGD[$i] & ")", $tvcID)
        GUICtrlSetState(-1, $GUI_FOCUS)
        GUICtrlSetOnEvent(-1, "TellMe")
        GUICtrlSetImage(-1, "shell32.dll", FindIcon($DGD[$i]), 2)
        GUICtrlSetImage(-1, "shell32.dll", FindIcon($DGD[$i]), 4)
        If $DGD[$i] = @HomeDrive Then
            $FL2A = _FileListToArray($DGD[$i], "*", 2)
            For $j = 1 To $FL2A[0]
                GUICtrlCreateTreeViewItem($FL2A[$j], GUICtrlRead($tvcID))
                GUICtrlSetImage(-1, "shell32.dll", -5, 2)
                GUICtrlSetImage(-1, "shell32.dll", -4, 4)
                GUICtrlSetOnEvent(-1, "TellMe")
            Next
        EndIf
    Next
EndFunc

Func FindIcon($dI)
    Local $DGT = DriveGetType($dI)
    Switch $DGT
        Case "Removable"
            If $dI = "a:" Or $dI = "b:" Then
                Return -7
            Else
                Return -8
            EndIf
        Case "Fixed"
            Return -9
        Case "Network"
            If DriveMapGet($dI) <> "" Then
                Return -10
            Else
                Return -11
            EndIf
        Case "CDROM"
            Return -12
        Case "RAMDisk"
            Return -13
        Case "Unknown"
            Return -54
    EndSwitch
EndFunc

Func _close()
    Exit
EndFunc

cheers

Edited by smashly
Link to comment
Share on other sites

Can everybody help me by the problem in post 1

When you say "name", do you mean the text of the item? if not the item doesn't have a name, it has an id.

SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...