Monday, January 16, 2006

Treeview AfterSelect and changing focus

When you want to set focus to another control in the AfterSelect method of a treeview there seems to be a problem with the behavior. Focus is set to the control but is then returned to the Treeview.

Forcing the Focus asynchronously seems to solve this little issue.


Add a delegate:

private delegate bool _methodInvoker();

Now in the AfterSelect handler add the following code:

myControl.BeginInvoke(new _methodInvoker(myControl.Focus));

Kept me busy quite some time :-(


Anonymous said...

Set the HideSelection property to false. Voila.

Anonymous said...

Actually, I'm talking crap. That doesn't work - you can however handle the mouse up event and do a hit test to see if a node was selected.

Anonymous said...

Enable a timer control from your after select event and set the focus/disable the timer in the click event.

Anonymous said...

wow, wish i found this article sooner
thanks !

Antonino Porcino said...

Thanks, it works nicely. The problems seems to affect other TreeView events too.