textbox.focus

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,
Can anyone explain why I the .focus method does not always work on a
textbox? I see that it executes briefly, but does not retain focus. Anyone
have any information on this?
regards,
Bill
 
When during the life cycle of a form are you calling .focus? This makes
a difference because the form itself gets the focus after the Form_Load
event.

-- John
 
It depends where you are calling it from. In some scenarios you can
workaround it by firing a very short timer and calling .focus in the tick
event handler.

Cheers
Daniel
 
Thank you both for replying.
I have a textbox, that takes a scan as input. After the scan is complete,
the textbox is disabled, so not to allow multiple scans, then a database call
is made based on the value of the scan. The response from the database fires
an event. This event enables the textbox and sets focus back to it(this is
the part that does not work)
 
Thank you both for replying.
I have a textbox, that takes a scan as input. After the scan is complete,
the textbox is disabled, so not to allow multiple scans, then a database call
is made based on the value of the scan. The response from the database fires
an event. This event enables the textbox and sets focus back to it(this is
the part that does not work)

Ah, it sounds like a timing issue. I suspect you need to let the screen
update after enabling the text box before you can set the focus.
Otherwise, the Focus method doesn't work because the text box hasn't
become focusable yet since it can't receive the focus when it's disabled.

As Daniel suggested, you could set a timer in the code that enables the
text box, then in the timer event handler, set the focus.

-- John
 
Just for fun :-) I set a timer and tried setting focus to the textbox on
every tick (2 seconds) I let this run for many minutes and no luck. I am at a
loss here on this one.
 
Use the Remote Spy utility that is installed with eMbedded Visual C++. You
should be able to capture messages for the main form window, if that's where
your problem is occurring and see what messages are going where. It could
be that the text box is rejecting focus, or that the current holder, at the
time that you call Focus(), is grabbing it back for some reason, but finding
out who is ending up focused is probably an important step in figuring out
'why'. It will also show when things get reenabled, relative to when the
focus operation is performed...

Paul T.
 
Back
Top