SetFocus to a control that is probably disabled
-
Long time ago, in a vb6 application I found this: Private Sub SetFocusControl(ByRef objControl As Control) Dim EnabledControl As Boolean EnabledControl = objControl.Enabled objControl.Enabled = True objControl.SetFocus objControl.Enabled = EnabledControl End Sub :wtf:
Marc R.
-
Long time ago, in a vb6 application I found this: Private Sub SetFocusControl(ByRef objControl As Control) Dim EnabledControl As Boolean EnabledControl = objControl.Enabled objControl.Enabled = True objControl.SetFocus objControl.Enabled = EnabledControl End Sub :wtf:
Marc R.
That person must have come from the Access world where you can't set the focus to a control unless it's Enabled first. IIRC, you couldn't even set the Text of a control unless it had the focus!
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
That person must have come from the Access world where you can't set the focus to a control unless it's Enabled first. IIRC, you couldn't even set the Text of a control unless it had the focus!
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
MarcR. wrote:
He is from c and c++ world...
I guess VB6 can do that to the best of us. BDF
-
Long time ago, in a vb6 application I found this: Private Sub SetFocusControl(ByRef objControl As Control) Dim EnabledControl As Boolean EnabledControl = objControl.Enabled objControl.Enabled = True objControl.SetFocus objControl.Enabled = EnabledControl End Sub :wtf:
Marc R.
-
Long time ago, in a vb6 application I found this: Private Sub SetFocusControl(ByRef objControl As Control) Dim EnabledControl As Boolean EnabledControl = objControl.Enabled objControl.Enabled = True objControl.SetFocus objControl.Enabled = EnabledControl End Sub :wtf:
Marc R.
Hi, I think control must be enabled then only we can set the focus.Because i faced this problem in one of my project. If the control is in diabled then we can't do any operation on it.if you want set focus on the control, it must be enabled as per the code which you written here. otherwise it throws the exception.... Any mistake pls forgive me.
Thanks and Regards Ganesan.S Software Engineer
-
Hi, I think control must be enabled then only we can set the focus.Because i faced this problem in one of my project. If the control is in diabled then we can't do any operation on it.if you want set focus on the control, it must be enabled as per the code which you written here. otherwise it throws the exception.... Any mistake pls forgive me.
Thanks and Regards Ganesan.S Software Engineer
The question is, why would you want to imperatively set focus on a potentially disabled control? It's like, are you giving a user a listbox that lists all of the controls on the form and when they select one, you set focus to it? I mean I could see how that's useful...like if you have 20 thousand controls on the form. But here's the real question...Why would you want to make a disabled control enabled? Maybe it was a handler for a checkbox and when the user checks the box, it enables a previously disabled control and sets the focus so the user...can...oh wait, it disables the control before the user can do anything.:doh: WTF?:confused: