Jump to content

Get selected item of an treelist


 Share

Recommended Posts

I'm starting an project and I with problems to get the selected item of an TreeList...

#include <_Array.au3>
#include <GuiTreeView.au3>


$Form1 = GUICreate("Form1", 633, 452, 193, 125)
$TreeView1 = GUICtrlCreateTreeView(32, 8, 273, 337)
$testing = _ArrayCreate("",GUICtrlCreateTreeViewItem("test1", $TreeView1),GUICtrlCreateTreeViewItem("test2", $TreeView1),GUICtrlCreateTreeViewItem("test3", $TreeView1))
GUICtrlCreateTreeViewItem("test-sub",$testing[1])
GUISetState(@SW_SHOW)


_GUICtrlTreeView_SelectItem($TreeView1, $testing[2], 0)
$item = _GUICtrlTreeView_GetSelection($TreeView1)
$teste = _GUICtrlTreeView_GetItemParam($TreeView1,$item)
MsgBox(0,'test',$teste)

I tried everything, but without Success.

Thanks in advance, AutoIt is awesome! :D

Link to comment
Share on other sites

#include <Array.au3>
#include <GuiTreeView.au3>


$Form1 = GUICreate("Form1", 633, 452, 193, 125)
$TreeView1 = GUICtrlCreateTreeView(32, 8, 273, 337)
$testing = _ArrayCreate("",GUICtrlCreateTreeViewItem("test1", $TreeView1),GUICtrlCreateTreeViewItem("test2", $TreeView1),GUICtrlCreateTreeViewItem("test3", $TreeView1))
GUICtrlCreateTreeViewItem("test-sub",$testing[1])
GUISetState(@SW_SHOW)


_GUICtrlTreeView_SelectItem($TreeView1, $testing[2])
$item = _GUICtrlTreeView_GetSelection($TreeView1)
$teste = _GUICtrlTreeView_GetItemParam(GUICtrlGetHandle($TreeView1),$item)
MsgBox(0,'test',$teste)
$teste = _GUICtrlTreeView_GetItemParam($TreeView1,$testing[2])
MsgBox(0,'test',$teste)

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

Thanks GaryFrost

someone can see my script and say where can I improve?

Ps: This is my first script... ^^

#include <GUIConstants.au3>
#include <GuiTreeView.au3>
#include <_Array.au3>
GUICreate("Link List", 350, 215)

$treeview       = GUICtrlCreateTreeView(6, 6, 100, 150, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$generalitem    = GUICtrlCreateTreeViewitem("Group1", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$links = _ArrayCreate("")


$add  = GUICtrlCreateButton("&Add", 35, 185, 70, 20)
$delete    = GUICtrlCreateButton("&Del", 105, 185, 70, 20)
$editar    = GUICtrlCreateButton("Edit", 175, 185, 70, 20)


GUISetState ()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
                
        Case $msg = $add  
                
                $item = GUICtrlRead($treeview)      ; Get the controlID of the current selected treeview item
            If $item = 0 Then
                MsgBox(64, "Link List Beta", "No item currently selected")
            Else
                $title = inputbox("Insert an title","Insert an title for the link","Link 1","",350,100)
                $link = inputbox("Insert an link","Insert the link","http://","",350,100)
                $group = inputbox("New Group?","Insert an name for an new group or N to Add in the selected","N","",350,100)
                if($title <>"" and $link <> "") then
                    if($group =='N') then   
                        if(_GUICtrlTreeView_Level($treeview,$item) <> 0) then
                            $group_to_add = _GUICtrlTreeView_GetParentParam($treeview,$item)
                        Else
                        $group_to_add = $item
                        endif
                        
                    else 
                        $group_to_add   = GUICtrlCreateTreeViewitem($group, $treeview)
                    endif
                $newitem   = GUICtrlCreateTreeViewitem($title, $group_to_add)
                msgbox(0,$newitem,$newitem)
                $new_array = _ArrayCreate($newitem,$title,$link,$group_to_add)
                    
                ReDim $links[$newitem + 1]
                $links[ $newitem ] = $new_array

                GUISetState ()
                $item = GUICtrlRead($treeview)
                If $item > 0 Then
                $hItem = GUICtrlGetHandle($item)
                DllCall("user32.dll", "int", "SendMessage", "hwnd", GUICtrlGetHandle($treeview), "int", $TVM_EXPAND, "int", $TVE_EXPAND, "hwnd", $hItem)
                endif
                    
                endif   
            EndIf
                
        Case $msg = $delete
        
            $item = GUICtrlRead($treeview)      ; Get the controlID of the current selected treeview item
            If $item = 0 Then
                MsgBox(64, "Link List Beta", "No item currently selected")
            Else
                if(_GUICtrlTreeView_Level($treeview,$item) <> 0) then   
                    GUICtrlDelete($item)
                else 
                    msgbox(0,"erro", "this Item can not be deleted")
                endif
            EndIf
            
        Case $msg = $editar
            $item = GUICtrlRead($treeview)      ; Get the controlID of the current selected treeview item
            If $item > 0 and IsArray($links[ $item ]) Then
               
                $item_value = GUICtrlRead($item)
                
                $db = $links[$item]
                $edit = inputbox("Edit title","Informe The new Title:",$db[1],"",350,100)
                $link = inputbox("Edit link","Informe The new Title:",$db[2],"",350,100)    
                if($title <>"" and $link <> "") then
                    GUICtrlSetData($item,$edit)
                    $new_array = _ArrayCreate($item,$edit,$link,$db[3])
                    $links[$item]= $new_array
                EndIf
                
            EndIf
            $item =''
        
    EndSelect
WEnd

GUIDelete()
Exit
Edited by darkhero
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...