troubleshooting Question

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

Avatar of RekhaShah
RekhaShah asked on
JavaScriptC#Node.jsMicrosoft Visual Studio* TreeView
2 Comments1 Solution22 ViewsLast Modified:
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.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros