TreeView, ItemParam and SetOnEvent

8 posts in this topic

CMJ 0

I have only been using Autoit for a few days but I am finding it fairly easy to pick up. I have run into my first snag though and I can't seem to figure this out.

I am having trouble with the GUICtrlSetOnEvent function. Below is a simplified version of the script that is not working. When you run this you will get a tree view with some test items. The problem is that if you click a sub item under #1, 2, 3, 4, 9 nothing happens but under #5, 6, 7, 8, 10 pressing click here will display the ItemParam (which is set to the item parent).

I am sure I am doing several things wrong but can anyone point me in the right directions on why the set event seems to work intermittently?

Share this post

Link to post

Share on other sites

Melba23 2,530

If you look at the example for _GUICtrlTreeView_SetItemParam in the Help file you see the following:

; Warning do not use SetItemParam on items created with GUICtrlCreateTreeViewItem

; Param is the controlId for items created with the built-in function

Basically when you use the UDF function you are overwriting the value that AutoIt uses to keep track of the Items it has created. This is why your GUICtrlSetOnEvent fails - AutoIt no longer has the data it requires to track the controls it created. Mixing built-in and UDF functions in this way often ends in tears.

Try this version where you do not overwrite the $iParam value set by AutoIt:

By the way, I also moved the GUISetOnEvent($GUI_EVENT_CLOSE, 'Close') line, so it had a GUI to refer to!

All clear? Please ask if not.

M23

P.S. You are not the CMJ from R4-TMS by any chance?

Edit: Added welcome.

Edited August 27, 2010 by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area

Share this post

Link to post

Share on other sites

CMJ 0

First, thanks for the quick reply and I will assume that since I do not know what R4-TMS is that it is not me.

But I guess that you have found the flaw in my logic. The problem is that I need to set a unique ID for each treeview item and when I saw the Set Param function I figured it would work. I need to be able to set this id and then recall it when the items is selected. The reason for all this is that I am generating my treeview from data in a sqlite db. This is working fine but the problem is that when the item is selected I would like to query the db using the item's unique id from the table (which is not displayed).

For Example: Let's say that I have a table that has a list of students. I am putting that list of students into my treeview and then when the student is selected I want to display the list of classes that the selected student is taking.

Grade 1

-Smith, Bill

-Jones, Tom

Grade 2

-Perkins, Suzy

-Jenkins, Jim

etc...

I figured that I could store the ControlID of each back in my db but it seems like there should be an easier way to store this id with the control and not display it.

P.S. To explain the R4-TMS reference. While replying to you I was listening to the gripping England-Pakistan Test match (that is cricket if you are not from one of the Test nations) on BBC Radio 4 - the programme is known as Test Match Special and one of the commentators is Chris Martin-Jenkins, more commonly referred to as CMJ. I did not really think that you were one and the same, but it amused me at the time.

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area

Share this post

Link to post

Share on other sites

storme 20

I've been using _GUICtrlTreeView_SetItemParam in one of my programs to save an array position and wondered why OTHER buttons were being pressed when I clicked in the tree. FINALLY found that the Param was the controlID and that is what was doing it.

I missed the

; Warning do not use SetItemParam on items created with GUICtrlCreateTreeViewItem

; Param is the controlId for items created with the built-in function

Comment in the example code.

Anyway my solution was just to add 100 to the arrey position and use that for the SetItemParam. Of course if I ended up with more than 100 controls on the form I was going to be in trouble again.

Share this post

Link to post

Share on other sites

Melba23 2,530

Delighted I could help you out - even if I did not realise it at the time!

I learnt about how AutoIt deals with TreeViews internally and the $iParam "problem" from this thread if you are interested.

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area

Share this post

Link to post

Share on other sites

CMJ 0

I've been using _GUICtrlTreeView_SetItemParam in one of my programs to save an array position and wondered why OTHER buttons were being pressed when I clicked in the tree. FINALLY found that the Param was the controlID and that is what was doing it.

I missed the

Comment in the example code.

Anyway my solution was just to add 100 to the arrey position and use that for the SetItemParam. Of course if I ended up with more than 100 controls on the form I was going to be in trouble again.

Your solution is MUCH more elegant and works perfectly!

THANK YOU!

I missed that comment too! Seems like it should be under the remarks section, No?

Share on other sites

Melba23 2,530

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort---- Sort arrays on multiple columnsChooseFileFolder---- Single and multiple selections from specified path treeview listingDate_Time_Convert-- Easily convert date/time formats, including the language usedExtMsgBox--------- A highly customisable replacement for MsgBoxGUIExtender-------- Extend and retract multiple sections within a GUIGUIFrame---------- Subdivide GUIs into many adjustable framesGUIListViewEx------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx------ Check/clear parent and child checkboxes in a TreeViewMarquee----------- Scrolling tickertape GUIsNoFocusLines------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify------------- Small notifications on the edge of the displayScrollbars----------Automatically sized scrollbars with a single commandStringSize---------- Automatically size controls to fit textToast-------------- Small GUIs which pop out of the notification area