|Subject||Re: [IBO] Moving Cell in TIB_grid|
> Thanks for remind me about this.And something else to remind you about...
You dont need to reply to both me and the group. Just reply to the
group and I will get a copy automatically. As you did it with this
message I got two copies.
> procedure TForm1.IB_Grid1KeyPress(Sender: TObject; var Key: Char);If only it were that simple. Keystrokes end up being processed in a
> if ord(key) = VK_RETURN then
> key := #9;
> Doesn't work
multitude of places and special keys like VK_RETURN are the most
complex of all - because so many controls want to do so much with
I did a _quick_ experiment and the following code works...
procedure TForm1.DoAppShortCut(var Msg: TWMKey; var Handled: boolean);
if (Msg.CharCode = VK_RETURN) and
(Screen.ActiveControl <> nil) and
( (IB_Grid1 = Screen.ActiveControl) or
(IB_Grid1.ContainsControl(Screen.ActiveControl)) ) then
IB_Grid1.Perform( WM_KEYDOWN, VK_TAB, 0 );
IB_Grid1.Perform( WM_KEYUP, VK_TAB, 0 );
Handled := true;
Setup this method (and add to the form declaration) and assign it to
Application.OnShortCut in the mainform create event.
There are LOTS of reservations about the above code.
Firstly, simulating keystrokes in this way is not always reliable, but
it appears to function OK in this instance. (It is always a good idea
to follow a keydown simulation with a keyup, since some controls
Secondly, it hard codes a particular grid (presumably on the mainform).
A more generic implementation would need code attached to the
Screen.OnActiveChange event to maintain a reference to the currently
active grid control (if any).
Thirdly, I am not certain what will happen when editing inplace using
either standard inplace editor on the grid or a control dropped on the
grid (like LookupCombo). There is a good chance that things will not
work as expected (due to the various controls wanting to use VK_RETURN
for their own use but never receiving it due to the above code). Such
problems may need a more sophisticated setup than described above.
Fourthly, I still think it is a bad idea :-)
Disclaimer: If the above code breaks some other functionality on the
grid or application do not expect the grid to be fixed to support it.
If something does not work as expected - remove this code and retest.
If this code is breaking something you will need to find a way to work
around the problem.
Geoff Worboys - TeamIBO