Button.Focus() method doesn't work (sometimes) 
Author Message
 Button.Focus() method doesn't work (sometimes)

SCENARIO:
I have a window used for time critical data entry that has several input
fields and buttons.  The users want the [ENTER] key to jump them to the next
logical field which may not be the next control in the tab order depending
on the data they entered.

MY SOLUTION:
I trap the [ENTER] key in the Form_KeyPress event then depending on the
field that has focus and the data that has been entered I set focus using
the Focus() method of the control I want the focus to move to.

Example:
   If TextBoxId.Text.Equals("") Then
      TextBoxName.Focus()
   Else
      ButtonSave.Focus()
   End If

PROBLEM #1:
This works great until I have to set focus to a button that was disabled
when the window first loaded (The button control's enable property was set
to False in the window designer so it would start off disabled).  I can
successfully TAB to the button but writing code such  as ButtonSave.Focus()
just jumps to the next control in the tab order after the ButtonSave control
that I actually wanted to receive focus.  If I enable the buttons in design
mode the code runs great, but that leads to a different problem (See PROBLEM
#2).

PROBLEM #2:
If the buttons are enabled in design mode and then I disable them in the
Form_Load event they are not visibly disabled on the window.  I tried to use
the Refresh() method after I disabled the buttons but they are still not
disabled.

This same basic design worked great in VB 6.  Is my logic flawed, is there
an easier way of doing this in VB.Net????



Fri, 07 Jan 2005 09:06:10 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. sometimes he does it sometimes he doesn't

2. TableDefs.Delete doesn't work sometimes

3. Toolbar Buttons Don't Work Sometimes

4. ActiveX-Exe: .Value=True doesn't work while direct click on button works

5. LostFocus doesn't go off when option button gets focus

6. oncomm doesn't work without focus?

7. Select method doesn't work properly

8. function doesn't work as a method...

9. close method on RegistryKey.OpenRemoteBaseKey doesn't seem to work

10. Help: AppendChunk method doesn't work

11. document.all method doesn't work

12. POST method doesn't work

 

 
Powered by phpBB® Forum Software