Subject | Re: [IBO] Moving Cell in TIB_grid |
---|---|
Author | TeamIBO |
Post date | 2002-02-11T00:57:27Z |
> 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
> begin
> if ord(key) = VK_RETURN then
> key := #9;
> end;
> 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
VK_RETURN.
I did a _quick_ experiment and the following code works...
procedure TForm1.DoAppShortCut(var Msg: TWMKey; var Handled: boolean);
begin
if (Msg.CharCode = VK_RETURN) and
(Screen.ActiveControl <> nil) and
( (IB_Grid1 = Screen.ActiveControl) or
(IB_Grid1.ContainsControl(Screen.ActiveControl)) ) then
begin
IB_Grid1.Perform( WM_KEYDOWN, VK_TAB, 0 );
IB_Grid1.Perform( WM_KEYUP, VK_TAB, 0 );
Handled := true;
end;
end;
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
expect it.)
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
Telesis Computing