How to check if control has focus?

RB Smissaert

Well-Known Member
Licensed User
Longtime User
How do I check if a control (in this case I am interested in the Table control) has focus? Is the only way to keep track with LostFocus and GotFocus via global variables and deduct the Table focus from that?

RBS
 

Cableguy

Expert
Licensed User
Longtime User
The simplest way is to have a flag, lets call it "FocusedControl"...
An in the "GotFocus" event add:

CheckFocused


Sub CheckFocused
FocusedControl=sender.name
'Do the checking you need done...

End sub
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I didn't know about the Sender object, but as the table control has no GotFocus event I have solved my problem know with GotFocus and LostFocus.
The only relevant controls were 2 textboxes and a table control, so no problem there.

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Thanks for the tip and I use the door library already to sort the table columns with a click on the headers and that works very nice. I noticed your code works with a timer and I am not keen to add that as I take it that there is some
overhead. Can't the door library check focus of controls without a timer?

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
The timer was just to show the state changing, when clicking either onto the table or the button, and noting else.

Ah, of course, I got it now!
Thanks again for the tip.

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
The Door method works nicely and quite simple, but I need to know the focus when I am clicking a menu item, so at that moment the table won't have focus.
So, I still will need to stick with the old method (tracking the textboxes focus) unless there was an event such as BeforeMenuClick.

RBS
 
Top