Solved

Can TreeView Contorl automatically focus and un-focus by user right-clicking on a node without changing it's selected node?

Posted on 2006-11-05
9
294 Views
Last Modified: 2010-04-16
Is there a property or do I have to write additional code for this behavior?  Basicly, The behavior like in Active Directory Users and Computer, if the root node is selected and has focus but I right click on like the Users folder, the Users folder would then be highlited and a pop-up menu appears pertains to the Users folder.  However, when I'm done wtih the pop-up of at this point I click on the empty area of the left pane, the root node would then again have the focus and it never lost the status as the "selected node"

Thanks.
0
Comment
Question by:lapucca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 11

Expert Comment

by:Expert1701
ID: 17879208
The TreeView control in version 2.0 of the .NET Framework works that way.
0
 

Author Comment

by:lapucca
ID: 17879273
I am using vs2005, .net 2.0.  Currently in my application's TreeView control, the selectedNode isn't changed when I right-click on another node and the pop-up menu for the clicked-node does pop up.  But, the right-clicked Node doesn't get the focus (The node is not highlited).  So it's looking weird with the selectedNode high-lited but my mouse is over the clicked-node.

Is there a property that I need to set or un-set?  Thanks.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17879293
Oh sorry, I did not read carefully enough: I thought the functionality you were looking for was the returning of focus to the root node (which it does), not the highlighting of the intermediate value.  When I set the HideSelection property to false, the TreeView works exactly like the Active Directory Users and Computers one.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:Mihai Stancescu
ID: 17880308
You can try this:

On the MouseDown event for the tree put this:

private void tree_MouseDown(object sender, MouseEventArgs e)
{
     if (e.Button == MouseButtons.Right && e.Clicks == 1) //make sure is only one right click... you can remove after &&
     {
         TreeNode aNode = tree.GetNodeAt(Cursor.Position.X,Cursor.Position.Y);
          if (aNode != null)
          {
                tree.SelectedNode = aNode;
          }
     }
}

Hope helps.
Regards,
Mishu
0
 

Author Comment

by:lapucca
ID: 17883399
I do have my HideSelection set to false.  When I right click on another node, the clicked-node does gain focus for a split seond when it's clicked but lose it back to the selected-node when the pop-up menu opens up.  The AD User and Computer snap-in retains the fous until the pop-up is closed or selected-menu action is done and performed.  Thanks.
0
 
LVL 11

Accepted Solution

by:
Expert1701 earned 500 total points
ID: 17885257
Your ContextMenuStrip must be assigned to each TreeNode, not the TreeView control.
0
 

Author Comment

by:lapucca
ID: 17887063
Oh, I can assign a contextMenustrip to a TreeNode?  Do I do this in the designer and how?  Currently, I'm calling the context menus when the node is clicked with button.  Maybe that is the problem with the focus?  Thanks.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17887327
You can only do this through the designer if your nodes are created at design-time.
0
 

Author Comment

by:lapucca
ID: 17891872
Ah, it does work that way.  I was able to assign it programmtically and it now works the way it should  thanks.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create a Dropdown list with sub group 10 43
ASP.NET data base connection 35 93
Pdf not loading 2 39
How to get the range for the percentage from user input. 4 25
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question