Sandip's Programming Zen

An attempt to share tech/coding experiences

Solution: Problem of focus when opening a Winform using Treeview node click

leave a comment »

I must blog this , since I could not find the fix as quickly as I should. So…
When you try to open a winform using treeview node selection (using any event like mouse_click on after_select) , the form opens, but it remains minimized even if you have set the focus and windowstate properties.  That is because treeview regains control after opening form, however there is no direct fix.  You can fix it by delaying the action of the event.

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
            this.BeginInvoke(new TreeViewEventHandler(delayedClick), sender, e);

        private void delayedClick(object sender, TreeViewEventArgs e)
             // your code goes here…

Original solution here.

Written by Sandip

January 6, 2011 at 4:12 pm

Posted in .Net

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: