PDA

View Full Version : Tree control with checkbox problem


bwalker
06-05-2009, 12:06 PM
I am using AMS 7.5.
I have a tree control with checkboxes, and I need to code some behavior in the "OnCheck" action based in which node is selected.
However, I have a problem where if the focus is on one node, and then the checkbox on another node is checked, the action fires on the checkbox but with the node which has focus rather than the node which has the checkbox.
It is not until after the checkbox is checked that the current node becomes the "selected" node.

Example:
Tree control with 5 nodes.
Focus (selected) is on node 2.
The user checks the checkbox on node 4, the code in the "OnCheck" action has a "strNode = Tree.GetSelectedNode("Tree_Control")" line in the first line of the script, and the valus of strNode is 2, rather than 4 where the checkbox was.

Is this a bug, or is there a workaround solution to this problem?

limboo
06-29-2009, 04:00 PM
there is a difference between selection and checking so it is certainly a thing for a further release, something like tree.getcheckednode
but what can you do?
go through al the nodes with a for loop and cycle through al the nodes tables to find the ones that are checked
I've also attached an example file

nodearray = {1, 1.1, 2, 2.1, 3, 4, 5} -- here you place all your node indexes make sure you don't make any mistakes because then the whole script doesn't work
checkedtable = {}
numberchecked = 0
for index, node in nodearray do
result = Tree.GetNode("Tree1", ""..node);
if result.Checked == true then
checkednode = node
numberchecked = numberchecked + 1
checkedtable[numberchecked] = ""..checkednode
end
end

--if you want to use the first table entry, and the first node
if checkedtable[1] == 1 then
--put your script here
end

--if you want to use the last table entry, and the last node
last = Table.Count(checkedtable);
if checkedtable[last] == 5 then
--put your script here
end

--if you want to find the second node in the table
for j,k in checkedtable do
if k == 2 then
--put your script here
end
end

limboo
07-05-2009, 02:17 PM
does it work for you?