Jump to content

GuiCtrlTreeView questions & problem


Recommended Posts

Hello im trying to create treeViewParents & childs based on what i have selected, it seem not to work properly, childs gets added to random places sometimes, does the array mess it up? or my selection method?

 

Also, when i try to delete, random items always gets deleted, cant really tell what the problem is..

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <GuiTreeView.au3>
#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
 
Local $aTreeView_Child[1]
$aTreeView_Child[0] = 1
 
#Region ### START Koda GUI section ### Form=c:\program files (x86)\autoit3\scite\koda\forms\script editor.kxf
Local $GUI = GUICreate("Form1", 763, 346, 337, 354)
$TreeView1 = GUICtrlCreateTreeView(8, 40, 457, 273)
 
$Button1 = GUICtrlCreateButton("Run selected", 8, 8, 83, 25)
$Button2 = GUICtrlCreateButton("Save", 96, 8, 75, 25)
$Button3 = GUICtrlCreateButton("Delete ", 208, 8, 75, 25)
$Button4 = GUICtrlCreateButton("Add", 472, 8, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
 
 
 
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button4
$tIndex = _GUICtrlTreeView_GetSelIndex($TreeView1)
ST_Editor_Add2List($TreeView1, $tIndex)
 
 
Case $Button3
$tIndex = _GUICtrlTreeView_GetSelIndex($TreeView1)
ST_Editor_RemoveFromList($TreeView1, $tIndex)
 
Case $Button1
MsgBox(0, 0, $tIndex)
_ArrayDisplay($aTreeView_Child)
 
EndSwitch
WEnd
 
 
 
Func ST_Editor_Add2List($TreeView, $iParent = 1)
 
 
_GUICtrlTreeView_BeginUpdate($TreeView)
If $iParent > 1 Then
_ArrayAdd($aTreeView_Child,_GUICtrlTreeView_AddChild($TreeView, $aTreeView_Child[$iParent], "Test " & Random(1, 10, 1), 0, 0))
Else
_ArrayAdd($aTreeView_Child,_GUICtrlTreeView_AddChild($TreeView, 0, "Test " & Random(1, 10, 1), 0, 0))
EndIf
_GUICtrlTreeView_EndUpdate($TreeView)
$aTreeView_Child[0] = UBound($aTreeView_Child) - 1
 
EndFunc   ;==>ST_Editor_Add2List
 
Func ST_Editor_RemoveFromList($TreeView, $index)
_GUICtrlTreeView_Delete($TreeView, $aTreeView_Child[$index])
EndFunc   ;==>ST_Editor_RemoveFromList
 
Func _GUICtrlTreeView_GetSelIndex($TreeView)
 
 
$iIndex = 0
 
$hItem = _GUICtrlTreeView_GetFirstItem($TreeView)
 
For $i = 0 To _GUICtrlTreeView_GetCount($TreeView) - 1
If _GUICtrlTreeView_GetSelected($TreeView, $hItem) Then $iIndex = $i + 1
;MsgBox(0,0,$hItem) /?!
 
$hItem = _GUICtrlTreeView_GetNext($TreeView, $hItem)
Next
 
MsgBox(64, "", StringFormat("Selected Text: %s\nSelected Index: %i", GUICtrlRead($TreeView, 1), $iIndex), 0, $GUI)
Return $iIndex
EndFunc   ;==>_GUICtrlTreeView_GetSelIndex

 

 
Edited by tarretarretarre
Link to comment
Share on other sites

Using code tags [ autoit] ; code here [ /autoit] (minus the spaces) will give you syntax highlighting and formatting. Making it easier for us to see. :)

like so:

Local $test = 'test' ; comment

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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...