PDA

View Full Version : Tree go previous node and go next node ?



ButtonMaker
04-05-2009, 02:56 AM
there is a problem with my code but i couldnt find it !!! i have 2 buttons "previous" and "next" for tree object;

previous button code :

nCount = Tree.GetChildCount("Tree1", "0");
if (nCount > 0) then
Tree.SetSelectedNode("Tree1", tostring(nInd));
MediaPlayer.Load("media1", Tree.GetNode("Tree1", nInd).Data);
if (nInd == nCount) then
nInd = 1;
else
nInd = nInd - 1;
end
end

next button code :

nCount = Tree.GetChildCount("Tree1", "0");
if (nCount > 0) then
Tree.SetSelectedNode("Tree1", tostring(nInd));
MediaPlayer.Load("media1", Tree.GetNode("Tree1", nInd).Data);
if (nInd == nCount) then
nInd = 1;
else
nInd = nInd + 1;
end
end


when i click next button it works ok and jumps the next node but once if i click the previous button it jumps to first node not the one before selected and then next button gives the same error !!!

Kick
04-05-2009, 07:07 PM
* On Click the button "Previous":

local strSelectedNode = Tree.GetSelectedNode("Tree1");
if (strSelectedNode ~= "") then
if (strSelectedNode == "1") then
nInd = Tree.GetChildCount("Tree1", "0");
else
nInd = tonumber(strSelectedNode) - 1;
end
Tree.SetSelectedNode("Tree1", tostring(nInd));
--MediaPlayer.Load("media1", Tree.GetNode("Tree1", tostring(nInd)).Data);
else
Tree.SetSelectedNode("Tree1", "1");
end

* On Click the button "Next":

local strSelectedNode = Tree.GetSelectedNode("Tree1");
if (strSelectedNode ~= "") then
if (tonumber(strSelectedNode) == Tree.GetChildCount("Tree1", "0")) then
nInd = 1;
else
nInd = tonumber(strSelectedNode) + 1;
end
Tree.SetSelectedNode("Tree1", tostring(nInd));
--MediaPlayer.Load("media1", Tree.GetNode("Tree1", tostring(nInd)).Data);
else
Tree.SetSelectedNode("Tree1", "1");
end