1

I have a problem with the FormGridControl.gotFocus method. The method works if the grid is empty. If the grid contains data it does'nt work...

I this a bug or can i do something else?

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
Frank
  • 147
  • 1
  • 9
  • 1
    What do you want to achieve? Describe your problem. See also http://stackoverflow.com/a/9296261/4509 – Jan B. Kjeldsen Jun 25 '14 at 10:08
  • 1
    I want to implement a command button for a grid (e.g. Command "Filter by Selection", 2844). But there is more than one grid on the form. So my first thought was: Check if GridA, GridB or GridC has the focus and than execute the click for the command button. But that didn't work (because the button has the focus if you click it...). So my workaround: I implemented i command button for EACH grid and set the focus to the grid. Now the Command button works fine... Or is there a better solution? Btw: I found the link before and you say don't use gotFocus - is there a special reason for it? Frank – Frank Jun 26 '14 at 07:08
  • Seems okay, though it is an unusual request in the first place. I cannot totally rule out `gotFocus` coding in very rare occasions. But most of the time it is the wrong path to go. – Jan B. Kjeldsen Jun 26 '14 at 08:39
  • Yes you are right. But did you know why gotFocus doesn't work properly? – Frank Jun 26 '14 at 09:07
  • Maybe a control in the grid got focus, not the grid itself. – Jan B. Kjeldsen Jun 26 '14 at 09:15
  • Hmm... There are no additonal controls there. – Frank Jun 26 '14 at 09:27
  • The grid control is a container containing other controls. – Jan B. Kjeldsen Jun 26 '14 at 09:28
  • Yes, of course... Anyway this "Event" did not work as I had expected. Seems to make no sense - gotFocus only raised if grid is empty :) – Frank Jun 26 '14 at 09:36

1 Answers1

2

The gotFocus on container controls may not be activated because a contained control got focus instead. Put another way: setting focus on a control does not activate the gotFocus methods of the containing container controls.

Thus it may be useless as tool for determining, what has focus.

Often a better way is to check the selectedControl of the FormRun class using the contains method:

boolean inGr = element.selectedControl() && group.contains(element.selectedControl());

This cannot be used in buttons of cause because the button gets focus when clicked!
It may be of use in the task method and other control methods.

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50