Click here to Skip to main content
14,211,427 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have an MDI form which contains a tree (docked left) which acts as a menu for opening MDIChild forms. When i click on a node of the tree (in NodeMouseClick event), a new MDIChild form is opened. The problem is that it does not receive the focus. The focus always remains on the tree. The MDIChild form does not have a Title and is maximized within the parent MDI form.

What I have tried:

I have tried using .Focus, Activate, BringToFront on the MDIChild form without any luck.

Is there a solution to this problem? Using .NET 4.0.3.
Updated 8-May-19 8:34am
Gerry Schmitz 8-May-19 15:22pm
The child order may not be what you think it is.
Member 10622063 8-May-19 15:41pm
It's not a matter of ordering. The first form that opens when i click on a node in the treeview, does not receive the focus as it should. The focus remains on the treeview on the MDI form, as if the treeview steels it.
Richard MacCutchan 8-May-19 16:53pm
It would help if you showed the code that sets the focus.
Dave Kreskowiak 8-May-19 17:50pm
My first thought was try setting the Focus on a control on the form instead of the form itself.
Gerry Schmitz 8-May-19 22:49pm
What's your "click" handler? The face-palm is usually that e.Handled is not set to true, causing the "default" behavior you see.
Member 10622063 9-May-19 3:40am
NodeMouseClick. No e.Handled there...
Member 10622063 9-May-19 3:50am
Private Sub Actions_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles Actions.NodeMouseClick
SourceForm.MdiParent = MDIForm
SourceForm.BringToFront() 'Has no effect
SourceForm.Activate() 'Has no effect
End Sub
Member 10622063 9-May-19 3:52am
I just tried it. No luck.

It appears that when the NodeMouseClick event is completed, the focus returns to the tree nomatter what you do...

EDIT: It seems that the control of the child Form i Focus, does receive the focus within the form, but the form itself still does not have the focus.
Member 10622063 9-May-19 4:20am
Even though i remember i had tried it, i tried it again, just to be sure. Nothing changed though...

After the .Show of the form, i added this:

I have also tried performing the above actions from within a Menu, and it worked fine. As long as i Focused on a button on the form, the form had the focus and pressing <space> i saw the button being pressed.

A TreeView bug perhaps?
Richard MacCutchan 9-May-19 4:43am
I have not used MDI in C# but I do remember using it in MFC, and moving the focus worked fine. Unfortunately that is a long way from .NET.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Wow! After a lot of searching in the last couple of days, i stumbled onto this: Tree control focus frustration | PC Review[^]

The proposal in the final post worked!

Thanks to everyone for the assistance.

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

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190619.1 | Last Updated 9 May 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100