View Full Version : Change 1 field in a whole list
Fenloh
May 17th, 2010, 11:11
Hi all,
I have run into a problem and i am not sure where my Problem lies.
there is a windowlist with several Items, but it should only be possible to haven 1 Item in the list "selected" via a Checkbox.
The goal is to select one Checkbox and deactivate the Checkbox in all other items.
Does anyone have a template where i can spy a little? I tried several approches but always ended in a loop or errormessage.
Fenloh
Moon Wizard
May 18th, 2010, 01:06
I haven't attempted anything like what you are saying yet.
Based on what you provided, I would have the checkbox change event (onValueChanged) call a function at the list level and pass the name of the child window database node name (not the control). Then, you can use the function at the list level to cycle through all the windows, make sure the selected window field is set, and make sure the unselected windows have that field disabled.
Also, you will need to have a boolean flag that gets set at the beginning of the list function in order to prevent an endless loop.
Perhaps something like the following code at the list level. Note: This is completely off the cuff and untested.
local bActiveLock = false;
function onActiveChanged(sChildNodeName)
if (not bActiveLock) then
bActiveLock = true;
for k, v in ipairs(getWindows()) do
if (v.getDatabaseNode().getNodeName() != sChildNodeName)
v.active.setState(false);
end
end
bActiveLock = false;
end
end
Cheers,
JPG
Fenloh
May 18th, 2010, 05:49
Hi Moon,
thanks for the Quick reply.
I tried it via the onFilter() function. I havent thought about defining an own arrray for that task.
another question wich bugged me :)
What is the meaning of the b, the s, the a in the Variables
like bActiveLock and sChildNodeName or aClienTargets and rTargets? I guessed, that they have a special Meaning for you, but i couldnt figure it out yet. Maybe if i do, then i will understand your RulesetCode a bit better :).
Fenloh
Fenloh
May 18th, 2010, 07:37
There is yet another Question.. why are you using ipairs instead of pairs? wouldnt I be be able to use pairs in the same manner, since getWindows() returns the Name and index in which the Index is already an integer Index?
Fenloh
Fenloh
May 18th, 2010, 09:08
Thanks Moon, works great.
only had to change some minor things. Also if you do not set the State for the clicked box it wouldnt change the Value.
Fenloh
local bActiveLock = false
function onActiveChanged(sChildNodeName)
if not bActiveLock then
for k, v in ipairs(getWindows()) do
if (v.getDatabaseNode().getName() ~= sChildNodeName) then
print (v.getDatabaseNode().getName());
v.ammunitioninusebox.setState(false);
else
v.ammunitioninusebox.setState(true);
end
end
bActiveLock = false;
end
end
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.