Hi to all,
i have e new need in my program.
In a form with AdvStringGrid i show the required data without problem.
Now, the new need, i have to let editing in only two columns and validate the input.
Here i have the problems .... more than one.
- The editing in rigth column start at normal click or after doubleclick?
It's unclared because sometime start after first click and sometime start after second (or third) click.
To reproduce do this: click on non edit cell, after click on editable cells (here somtime edit start at first click and sometime to second), change cell and back .... same as above. - After finish editing start validate event .... and late? Which event is fired? Seem to go back to CanEdit event.
- How i can do to stop editing in case on not valid input?
In my program, when the form is open, the grid is NOT focused and the editable columns are, for example, 3 and 5.
here my events ... (SG1 is TAdvStringGrid and column5 is editable only if chckbox Chk2 is false);
This event is fired to enable edit in rigth column, it's fired up with one or double mouse click
procedure TForm1.SG1CanEditCell(Sender: TObject; ARow, ACol: Integer;
var CanEdit: Boolean);
begin
if (ACol=3) or ((ACol=5) and Not (Chk2.Checked)) then
begin
CanEdit:=True;
end
else
CanEdit:=False;
end;
If is valid i input some text and this is the event to validate
procedure TForm1.SG1CellValidate(Sender: TObject; ACol, ARow: Integer;
var Value: string; var Valid: Boolean);
begin
if ACol=3 then
begin
Valid:=True;
end
else
if ACol=5 then
Begin
// this is valid only if another cell's (4) value is set to 'N'
if SG1.Cells[4,ARow]='S' then
begin
Valid:=False;
// No way to exit from cell edit even with "esc" key
end
else
begin
Valid:=True;
end;
end;
end;
There's a way to start edit ONLY after a doubleclick on rigth cell ?
The other option, who i used in other project, is allow edit in onther form and not use inplace edit (that in this case is very appreciate).
Hope you can reproduce this ....
Thank's for attention
Regards
Daniele