Click here to Skip to main content
15,868,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I have a little problem while i am making my software in .NET 4.6 using WinForms.
I'm trying to set focus on richtextbox after i click a treenode and keep it on it.
When i run my software and click a treenode the focus did go to the richtextbox but then it return to the treeview.
I didn't code treeview to get the focus after set the focus to richtextbox. i found that if i set message box after i gave richtextbox focus to check if treeview is focused or not. The focus stay on richtextbox but if there isn't message box i always return to treeview.

The treeview and richtextbox both in a splitContainer.

Basically, my software is a note taking software and i show the folders and notes in a treeview. The user will click a treenode to open the selected note in a richtextbox. I want to make richtextbox focused but the focus always return to treeview after it focus the richtextbox if i select the treenode by click. But if i used up or down keys on keyboard the focus stays on the richtextbox.

How to keep the focus on the richtextbox when i click on a treenode to open a note?

What I have tried:

I follow the code to see if i somewhere make treeview focused but it isn't.
Posted
Updated 14-Nov-18 3:15am

1 solution

I dislike the TreeView control for many reasons, but this is a new one... :sigh:

You can do it, but it's a major kludge:
C#
private void myTreeView_Enter(object sender, EventArgs e)
    {
    myRichTextBox.Focus();
    }
Comment it well ... or you'll remove it later!
 
Share this answer
 
Comments
Sami Jildeh 14-Nov-18 10:40am    
I tried your suggestion, i add some conditions as i don't want it to focus RTB everytime the user enter the tree.

But it works (as temporary solution) with my conditions and the focus stays on the RTB. As i need to know what happens that the treeview get the focus.

Thank you.
OriginalGriff 14-Nov-18 10:45am    
You're welcome!
It's a PITA the TreeView Control ... I think the MS Intern was incharge of developing it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900