Good morning to all,
in my grid i need to allow edit only in 3 columns.
Two are contiguous, the last one no.
The effect who i try to get is, with the arrow key or mouse, move the cursor only in this 3 cells.
For example for 10 columns grid only the 3,4 and 7 are editable.
When the form is showed, by defaut, the grid start with the cursor in cell[3,1], so if j press the left key nothing append, if i press the rigth key go to column 4 and if i press the rigth key again the curso need to move (jump) to column 7.
I try to do this via CellChanging event, but i'm not able to jump from column 4 to 7
Here my event
procedure TFMRG.SG1CellChanging(Sender: TObject; OldRow, OldCol, NewRow,
NewCol: Integer; var Allow: Boolean);
begin
Allow:=False;
if (NewCol=3) or (NewCol=4) or (NewCol=7) then Allow:=True
else
if NewCol=5 then
begin
NewCol:=7;
Allow:=True;
end;
end;
In this case the curso move to column 5, even newcol is setted to 7 (this is rigth because NewCol is not VAR).
Is it possible to get this "effect"?
If yes ... how ?
Thank's for your reply.
Regard
Daniele
The mistake here is
that NewCol, NewRow are not var parameters. So, either, when you set Allow =
true, the grid will move to NewCol,NewRow itself and when you set Allow =
false, you need to programmatically update the new focused cell yourself from
this event, i.e. by setting grid.Col / grid.Row properties.
You'd need to handle from here left & right arrow key handling, so to jump over columns 5, 6 something like:
if (OldCol < NewCol) and (NewCol=5) then
begin
advstringgrid1.Col := 7;
Allow := false;
end
else
if (OldCol > NewCol) and (NewCol=6) then
advstringgrid1.Col := 4;
Hi Bruno,
thank's ..... i didn't think !!!!
Daniele