Sign in to follow this  
Followers 0
twbradio

OK, Treeview one more time - but with an example

5 posts in this topic

CODE
#include <GuiConstants.au3>

#include <Array.au3>

#Include <GuiTreeView.au3>

#include <Date.au3>

Opt("GUIOnEventMode", 1)

Opt("TRAYICONHIDE", 1)

global $test, $tree1, $branch1, $branch2, $leaf1, $leaf2, $leaf3, $leaf4, $leaf5, $leaf6, $count=0

$test = GUICreate("test window", 200, 200 )

GUISetOnEvent ($GUI_EVENT_CLOSE, "exiter")

$tree1 = GUICtrlCreateTreeView( 1, 1, 198, 198 )

$branch1 = GUICtrlCreateTreeViewItem ( "Branch 1", $tree1 )

GUICtrlSetOnEvent($branch1, "branch" )

$leaf1 = GUICtrlCreateTreeViewItem ( "Leaf 1a", $branch1 )

GUICtrlSetOnEvent($leaf1, "leafa" )

$leaf2 = GUICtrlCreateTreeViewItem ( "Leaf 1b", $branch1 )

GUICtrlSetOnEvent($leaf2, "leafb" )

$branch2 = GUICtrlCreateTreeViewItem ( "Branch 2", $tree1 )

GUICtrlSetOnEvent($branch2, "branch")

$leaf3 = GUICtrlCreateTreeViewItem ( "Leaf 2a", $branch2 )

GUICtrlSetOnEvent($leaf3, "leafa")

$leaf4 = GUICtrlCreateTreeViewItem ( "Leaf 2b", $branch2 )

GUISetState (@SW_SHOW)

While 1=1

sleep (500)

WEnd

exit

func branch ()

MsgBox (1, "Parent CID is", _GUICtrlTreeViewGetParentID ($tree1, @GUI_CtrlId))

EndFunc

func leafa ()

MsgBox (1, "Parent CID of leaf typea is", _GUICtrlTreeViewGetParentID ($tree1, @GUI_CtrlId))

EndFunc

func leafb ()

Select

Case $count = 0

$leaf5 = _GUICtrlTreeViewInsertItem ($tree1, "Leaf 1c",$branch1, $leaf2)

GUICtrlSetOnEvent ( $leaf5, "leafc" ) ;I know this won't work because $leaf5 is a handle and not a control ID

GUICtrlSetOnEvent ( $leaf4, "leafb" )

GUICtrlSetOnEvent ( $leaf2, "" )

$count = $count +1

Case $count = 1

$leaf6 = _GUICtrlTreeViewInsertItem ($tree1, "Leaf 1c-1",$leaf5 )

GUICtrlSetOnEvent ( $leaf6, "leafc" )

$count = $count +1

MsgBox (1, "CID of leaf 1c is:", _GUICtrlTreeViewGetParentID ($tree1, $leaf6)) ;this should give me the CID of leaf 1c, but doesn't

GUICtrlSetOnEvent ( _GUICtrlTreeViewGetParentID ($tree1, $leaf6), "leafc" ) ;this fails because I do not have a CID for leaf 1c

GUICtrlSetOnEvent ( $leaf2, "leafb" )

EndSelect

MsgBox (1, "Parent CID of leaf typeb is", _GUICtrlTreeViewGetParentID ($tree1, @GUI_CtrlId))

EndFunc

func leafc ()

msgbox (1, "leaf type c", @GUI_CtrlId)

EndFunc

func exiter ()

Exit

EndFunc

First things first, this is not a real smaple of how I code - it is just a quick throw together for this discussion's sake.

I have a problem ... I need to be able to dynamically create treeview items, and then be able to do something with them. I am using On-Event mode due to the number of elements that I am creating for this script (with treeviews, the number of elements gets very large quickly). In addititon, 1300 lines in is not a good place to try to make the change either. In the example script, you can click on just about anything, and something will happen, but, to test the behavior - click on leaf 1b to create leaf 1c and then click on leaf 2b to create leaf 1c-1 and pop up a message box with it's parent's contol ID (leaf 1c). The message box output indicates what I suspected - that the inserted treeview items do not have control ids. This makes trapping any event in which these new items are selected difficult to do. Any ideas are welcome.

Tom Brown


Anyone have a TRS 80 Model III for sale?

Share this post


Link to post
Share on other sites



This is what I used when I was dynamically creating the treeviewitems and it worked for me. Try it out.....Treeview Example (Thanx to MHz)

Thank you vey much for the response ... I had looked at your post before, but not really dug into the way your routine was working. There are several ideas that I may be able to use in the future; unfortunately, having checked it out, it doesn't seem to work with treeview items created with _GUICtrlTreeViewInsertItem.

I inserted the following two lines into your code as a test...

_GUICtrlTreeViewInsertItem ($Treeview, "Leaf 1c",$Tree_Parent_Split[1]) below GUISetState() in the main routine

msgbox (1, "", $nCtrl&" "&$hItem&" "&$nItem) in the GetChilds function ... just below the call for GetItemID.

The output for the _GUICtrlTreeViewInsertItem item returns a ControlID of 0. My challenge is that I need to add items to a treeview, and then know when that item is selected so that I can update an associated display.


Anyone have a TRS 80 Model III for sale?

Share this post


Link to post
Share on other sites

Instead of using _GUICtrlTreeViewInsertItem, I would use GUICtrlCreateTreeViewItem.

Share this post


Link to post
Share on other sites

Instead of using _GUICtrlTreeViewInsertItem, I would use GUICtrlCreateTreeViewItem.

But what about the limit with controls creating (Maximum number of GUI controls per window: 4096)?

Is someone manage to solve this issue? i wondering to, how we can set an event for item that created (inserted) with _GUICtrlTreeViewInsertItem() ?


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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