When using datagrid for data entry using a database adapter, and using inplace editors (TTMSFNCDataGridComboBox) I had a problem similar to what I've already seen in FNC Grid / AdvGrid: hide inplace editors.
I had to call MyGrid.StopEditing from within my DataSet's events: BeforeCancel, BeforeClose, BeforeDelete, BeforePost & BeforeRefresh. Is there a more practical way to do this ?
Post is called when switching rows, not sure what triggers all the before events, can you provide some more details on what properties you set? What behavior you expect and see?
I am having a similar issue with fncgrid by double clicking row 1 cell 2 then hit ctrl c. to copy the value then exit grid how to force an cancel edit on that grid when exiting that grid?
fnc grid
I tried the grid exit event using.grid.StopEdit;
and Grid.EndUpdate; however, the editing field turn white and you cannot see the value in field.
I knew that about grid.endupdate, but I was trying several things. The issue is when I use grid.exit event with grid.stopedit and I click the cell twice to edit, the cell turn white in color and I cannot see the value in that cell and if click on the next cell it changes the color to white and hides that value also. At this point, I have to restart the app. This only happens with the grid.exit event. This FNC Grid is editing but I do not use the grid post.
procedure TForm1.FormShow(Sender: TObject);
begin
fdtable6.Close;
fdtable6.Open;
end;
procedure TForm1.TMSFNCGrid1CellEditDone(Sender: TObject; ACol, ARow: Integer;
CellEditor: TControl);
begin
TMSFNCGrid1.BeginUpdate;
if (ACol = 0) and (Arow = TMSFNCGrid1.FocusedCell.Row) then
BEGIN
fdtable6.Edit;
fdtable6.FieldByName('ID').AsINTEGER := STRTOINT(TMSFNCGrid1.Cells[Acol, Arow]);
END
else
if (ACol = 2) and (Arow = TMSFNCGrid1.FocusedCell.Row) then
BEGIN
fdtable6.Edit;
fdtable6.FieldByName('DEFSITE').AsSTRING := TMSFNCGrid1.Cells[Acol, Arow];
END
else
if (ACol = 1) and (Arow = TMSFNCGrid1.FocusedCell.Row) then
BEGIN
fdtable6.Edit;
fdtable6.FieldByName('NUM').AsSTRING := TMSFNCGrid1.Cells[Acol, Arow];
END
else
if (ACol = 3) and (Arow = TMSFNCGrid1.FocusedCell.Row) then
BEGIN
fdtable6.Edit;
fdtable6.FieldByName('DESCRIPTION').AsSTRING := TMSFNCGrid1.Cells[Acol, Arow];
END;
try
fdtable6.POST;
except
on E: Exception do
begin
showmessage('Exception Raised Part RECORD with message : '+ #13#10 + E.message);
fdtable6.Cancel;
end
end;
TMSFNCGrid1.EndUpdate;
end;
procedure TForm1.TMSFNCGrid1Exit(Sender: TObject);
begin
TMSFNCGrid1.StopEdit;
end;
When starting editing, you already get OnExit of the grid, because the inplace editor wants focus, which means the event is triggered and immediately cancels editing. The thing is, when connected to a database adapter, it does not allow canceling the edit. You can use the following code instead:
procedure TForm1.TMSFNCGrid1BeforeCellEditExit(Sender: TObject; ACol,
ARow: Integer; CellEditor: TTMSFNCGridEditor; var AllowExit: Boolean);
begin
AllowExit := True;
end;