Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

String grid keypresses

420 views
Skip to first unread message

Alex

unread,
Mar 10, 2000, 3:00:00 AM3/10/00
to
Hi

When editing a cell in a String grid, it handles navigational key presses
differently depending whether A) whole text of a cell is highlighted or B)
none or part of text highlighted. In case of B cursor moves within the cell.
In case of A highlighting moves to another column.

I have one editable column only. So to the user it looks like keyboard is
not working, when he presses say left key while the whole text of the cell
is highlighted.

Is there any way to change this stringgrid behavier, eg. to not allow
movement between columns by pressing left,right,home,end keys whilst editing
text in a cell, and instead let the cursor move withing the cell across
edited text.

The grid I am using is actually a simple component derived from TStringGrid.
Took me a while to figure out that nothing was wrong with my component code,
but it was just a stuck attempt to move between columns in a single column
grid.

Thanks
Alex

Peter Below

unread,
Mar 10, 2000, 3:00:00 AM3/10/00
to
In article <8a9fft$gu...@bornews.borland.com>, Alex wrote:
> When editing a cell in a String grid, it handles navigational key presses
> differently depending whether A) whole text of a cell is highlighted or B)
> none or part of text highlighted. In case of B cursor moves within the cell.
> In case of A highlighting moves to another column.
> I have one editable column only. So to the user it looks like keyboard is
> not working, when he presses say left key while the whole text of the cell
> is highlighted.

Try to set the AlwaysShowEditor option to true. The problem is that the
inplace editor is not yet active when the complete cell is selected, so a
arrow key press moves to the next cell. Once the editor is active (EditorMode
= true) the editor itself handles the arrow keys.

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Sent using Virtual Access 5.00 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Alex

unread,
Mar 11, 2000, 3:00:00 AM3/11/00
to
EditorMode is TRUE and AlwaysShowEditor too. I actually set it myself in
code when needed.

Here is the scenario. Have it all set to true. Edit text as you wish. Then
just highlight it by say pressing home and then shift-end. After this use
arow keys, highlighting will move to another column.

If you have one editable columns the effect will be such that keyboard not
working.

Alex

"Peter Below (TeamB)" <10011...@compuXXserve.com> wrote in message
news:VA.000049f...@antispam.compuserve.com...

Peter Below

unread,
Mar 11, 2000, 3:00:00 AM3/11/00
to
In article <8ac9bu$jd...@bornews.borland.com>, Alex wrote:
> EditorMode is TRUE and AlwaysShowEditor too. I actually set it myself in
> code when needed.
> Here is the scenario. Have it all set to true. Edit text as you wish. Then
> just highlight it by say pressing home and then shift-end. After this use
> arow keys, highlighting will move to another column.

As it turns out this is intended behaviour programmed into the inplace editor
control. In its KeyDown method it has

VK_LEFT: if ForwardMovement and (Ctrl or LeftSide) then SendToParent;
VK_RIGHT: if ForwardMovement and (Ctrl or RightSide) then SendToParent;

Forwardmovement returns true if the goAlwaysShoweditor option is set, Ctrl
returns true if the Ctrl key is down, LeftSide/RightSide return true if the
caret is after the last (before the first) character in the cell *or* if all
text is selected. So the parent gets the key and moves to the next cell.

There are two possible fixes: the first is not to use goAlwaysShoweditor (so
my advice in the first reply was wrong). However, this looses the ability to
move between cells using the arrow keys, so is not optimal. The second fix is
to unselect the text as soon as the cell is activated. That can be done with
a handler for OnSelectCell and a bit of messaging, as shown in the following
sample unit:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;

const
UM_UNSELECTEDITOR = WM_USER + 121;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
private
{ Private declarations }
Procedure UMUnselecteditor( Var msg: TMessage ); message
UM_UNSELECTEDITOR;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
close
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
// need to delay action until the cell editor is active, which it is
// not here.
PostMessage( handle, UM_UNSELECTEDITOR, 0, 0 );
end;

type
gridcracker= Class( TStringgrid );
// need that to gain access to protected InplaceEditor property

procedure TForm1.UMUnselecteditor(var msg: TMessage);
begin
with gridcracker(stringgrid1) do
if editormode then
inplaceEditor.deselect;
end;

end.

0 new messages