Change of Focus from one control to the other

G

Glyn Meek

I'm sure this is a simple thing to do, and I should know it...but I don't,
so any help would be appreciated.

I have two controls on a form, one is a listview, one is a text box. I
normally accept the entries into the textbox one keystroke at a time through
a user defined event handler for 'keypressed', and the textbox has 'focus'
(i.e. the cursor sits in the textbox at the end of the entered text.)

The user can click on the listview box at any time, and then I recognize the
selected item and go off and process this in an event handler for
'selectedindexchanged'. After processing this event, I then want the focus
to go back to the textbox and to have the cursor once more sitting flashing
at the end of the entered text, waiting for use input of the next
character...

BUT...I can't figure out how to get this focus back to the textbox.

I have tried making the last statement in the listview
'selectedindexchanged' event handler to be

textbox.focus()

(Actually, I think I've tried every event I can for the textbox...:)...but
nothing seems to work, focus still remains in the listview control)

but this has no effect. The only way I can do it is to 'click' on the
textbox with the mouse after the listview event has been handled, but this
is 'unfriendly' for the user.

What am I missing here.

regards

Glyn J Meek
 
J

Jim Brandley

In my experiments with setting focus, it often failed. So I stored the
controlID, and set a timer to fire, which then altered the focus. Somewhere
in the 500 - 700 ms range seems to work every time. I think the browser gets
busy with event processing, and the focus request gets lost.
 
G

Glyn Meek

Jim...excellent idea, and I have used timers a fair bit on other 'stuff'.
When you mention sotring the control id and then setting the timer to fire,
can you give me a smidgen more idea here as to what you do when you have
stored the controlID, and what does the timer activate when it fires?

Regards and many thanks

Glyn
 
E

ed l

Placing

if textbox.visible then textbox.focus


in the MouseUp event for the ListView seems to work the best for me.


It also seems work in KeyUp but that introduces the problem of
transfering
control to the textbox when the user is using arrow keys to navigate
through
a cell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top