PC Review


Reply
Thread Tools Rate Thread

Change of Focus from one control to the other

 
 
Glyn Meek
Guest
Posts: n/a
 
      16th Jan 2005
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


 
Reply With Quote
 
 
 
 
Jim Brandley
Guest
Posts: n/a
 
      17th Jan 2005
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.

"Glyn Meek" <(E-Mail Removed)> wrote in message
news:EfxGd.8885$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Glyn Meek
Guest
Posts: n/a
 
      17th Jan 2005
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


"Jim Brandley" <(E-Mail Removed)> wrote in message
news:e2JPivN$(E-Mail Removed)...
> 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.
>
> "Glyn Meek" <(E-Mail Removed)> wrote in message
> news:EfxGd.8885$(E-Mail Removed)...
>> 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
>>
>>

>
>



 
Reply With Quote
 
ed l
Guest
Posts: n/a
 
      20th Jan 2005

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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
change focus to sub form's control Shetty Microsoft Access Form Coding 1 14th Jan 2008 07:55 PM
Control's, Focus, and Change focus Jon Slaughter Microsoft C# .NET 4 19th Nov 2006 12:31 PM
Change focus to control John Barnes Microsoft Access 3 2nd Dec 2004 02:29 PM
Change focus to UI control VC++6 =?Utf-8?B?TmV3Ymll?= Microsoft VC .NET 0 23rd Jun 2004 09:15 PM
Unable to set focus to control on tab change Chris Beach Microsoft C# .NET 0 15th Apr 2004 06:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:30 PM.