Link to home
Start Free TrialLog in
Avatar of RekhaShah
RekhaShah

asked on

Previous butoon click takes focus to previous sibling node not the last childnode of the previous node.

I have a treeview control and a tab control  on my winform and using C# in Visual Studio 2019.
I am trying to move up and down the treeview nodes by clicking Next and Previous button on each page of the tabcontrol.
I am using Inputsimulator from Nuget also.
My treeview node as 3 levels,Root, Nodes and nodes children.
e.g.
System(root)
     Node 1 TypeA(1)
     Node 2 TypeA(2)
     Node 5 B
     Node 6 B)
          Child 1
          Child 2
     Node 7 B
          Child 1
          Child 2
   Node 8 B




     
   private void btnPrevious_CPU_Click(object sender, EventArgs e)
        {

            string CurrentnodeName = trvwBDA.SelectedNode.Name;

            SavePageContent(nCurrentCPUNode);

            string sNodeName;
            TreeNode TN;
            SelectTreeViewNode(CurrentnodeName);
            trvwBDA.Focus();

            if (trvwBDA.SelectedNode.PrevNode == null)
            { TN = trvwBDA.SelectedNode.Parent; }
            else
            {
                TN = trvwBDA.SelectedNode.PrevNode;
            }
            trvwBDA.Focus();
            InputSimulator sim = new InputSimulator();
            sim.Keyboard.KeyPress(VirtualKeyCode.UP);
            trvwBDA.Focus();
           
            HandleTreevoewNodeClick(TN, out sNodeName);
            SelectTreeViewNode(TN.Name);
            trvwBDA.Focus();


I am trying to move up and down the treeview nodes with Next-Previous button.. If i dont call SavePageContent routine( that is if treeview does not lose focus and does not get rreloaded, it works just fine. but when i try to come back to the treeview to the previously saved node, on "Previous" click, it goes to previous sibling node instead last child of the previous node. in this example, if i click  on Node 8B, it goes not Node 7B instead of Child 2 of Node 7B,  How do i fix it? i spend so much time on this, i give up.
Please hlep
Thanks in advance.
Avatar of RekhaShah
RekhaShah

ASKER

Never Mind,

I just had to use the following code instead of looking for parent or sibling node in my previous button clidk.
TreeNode nodex = trvwBDA.SelectedNode;
 TN = nodex.PrevVisibleNode;
ASKER CERTIFIED SOLUTION
Avatar of RekhaShah
RekhaShah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial