Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Weird focus problems with TreeView

I have a treeview control - somewhat like microsoft outlook.
The control has 4 buttons. On clicking a button, a screen launches. The focus then moves to the first control in the tab order.

Only problem is that its not working that way. The screen launches. But the focus remains on the treeview button that was clicked. Even if i explicitly set the focus to the first control in the tab order, the focus remains on the treeview.

I use the function cmbMaterial.Focus() but it does not work as explained above. cmbMaterial is the control first in the tab order. I set the focus on Form Load even that handles MyBase.Load

How do i kill the focus from the treeview and set it to the object i desire?

Friday, January 14, 2005

Control focussing in .net drives me mad. I can't get it to work. Setting focus in the form load never seems to work. It's almost as if you can only set it once it's displayed.. But then with modal dialogs you're buggered. Anyone, no easy answers that I've found. If someone has some insight then for god's sake spit it out!

Saturday, January 15, 2005

Are you setting before or after postback?

if the control postback, you'll probably have to set focus on the reload of the page

Sunday, January 16, 2005

gwyn :

For some reason i can't get focusing to NOT work right now, but I've had the problem in the past. What I usually do is something like this:

In the form where I want to set focus:

        protected override void OnLoad(EventArgs e)
            this.BeginInvoke( new MethodInvoker( SetFirstControlFocus ) );
            base.OnLoad (e);

        private void SetFirstControlFocus()

...replace 'button1' with whatever control you want to give initial focus.

Monday, January 17, 2005

I am sorry. This is not a web application. I was talking about a simple client server application

Monday, January 17, 2005

*  Recent Topics

*  Fog Creek Home