Control edited data
Control data input in the InplaceEditor
After the user has entered the data in the cell editor and press Enter, or tried to move to the next cell the grid transfers the data entered from the editor in the Field like this Field.AsString := InplaceEditor.Text.
Before the data transfer the TColumnEh.OnUpdateData event occurs, where you can perform additional checks, replace the text or to take on itself the management of data entry in the field Field.
The event has the following parameters:
Sender: TObject
var Text: string
var Value: Variant
var UseText: Boolean
var Handled: Boolean
In this event, you can change the Text and the Value that will record in the DataSet. You can also change UseText value to indicate which parameter should be used for recording. If it is used Value parameter, the recording will TField.AsVariant property to write value.
You are free to write the value in the field using the following code:
procedure TForm1.DBGridEh1Columns2UpdateData(Sender: TObject; var Text: string;
var Value: Variant; var UseText, Handled: Boolean);
begin
if UseText
then TColumnEh(Sender).Field.AsString := Text
else TColumnEh(Sender).Field.AsVariant := Value;
Handled := True;
end;You can also directly call the DataSet.Post to finish editing the recording immediately after recording the data in the field.
