Edit Events

Editing process is started after user click on cell, or start typing while cell is selected. In both cases public method EditCell is called.

There are several events used in editing cell process. They are occur in next order:


Triggered before editing is started.

Accept parameter can be set to False in order to prevent editing.
Text can be adjusted to custom text (different than one in underlaying cell).

procedure TForm1.NextGrid61BeforeEdit(Sender: TObject; ACol, ARow: Integer; var Accept: Boolean; var Text: WideString); begin // Set default text inside edit in case if cell is empty if Text = '' then Text := 'Default'; // Prevent editing first 2 rows if ARow < 2 then Accept := False; end;


Editing is started, but in-place editor control is not yet set.

This event provide var InplaceEdit parameter which allows switching (or even creating) component to be used as editor.

procedure TForm1.NextGrid61GetInplaceEdit(Sender: TObject; ACol, ARow: Integer; var InplaceEdit: INxInplaceEdit); begin if ACol = 1 then begin { Set `InplaceEdit` var arg. } InplaceEdit := TListBoxEdit.Create(Self); end; end;
If InplaceEdit is not nil, editing will start. EditingCell property is also set.

TListBoxEdit class used in example is TListBox descendant with INxInplaceEdit implementation.


InplaceEdit component is inserted (Parent property is set) into Grid.

This event provides opportunity to further adjust inplace-edit component with Component parameter.

It's called before Text is set, so this event is good place for tasks such as adding Items before ItemIndex is set.

procedure TForm1.NextGrid61InplaceEditInsert(Sender: TObject; ACol, ARow: Integer; Component: TComponent); begin if ACol = 1 then begin with Component as TListBoxEdit do begin Items.Add('George'); Items.Add('Lucia'); Items.Add('Michael'); Items.Add('Ann'); Items.Add('Ben'); end; end; end;
InplaceEdit is positioned, shown and focused.


Editing is started.


Occurs after edit's value, or some other important property is changed. When this event is triggered depends on specific implementation but it is usually after user change value.


Occurs before Edit's value is transferred back to the cell. Var (in/out) parameters can be altered in order to prevent transfer of new value, or block user from exit editing (CanLeave parameter).

procedure TForm1.NextGrid61AcceptEdit(Sender: TObject; ACol, ARow: Integer; var Text: WideString; var Accept, CanLeave: Boolean); begin // Don't allow empty text to be transfered. if Trim(Text) = '' then begin Accept := False; // Value is not accepted Text := 'default'; // Inject default value into edit CanLeave := False; // Prevent leaving editing state Beep; // Alert user with sound end; end;


Occurs after In-place Edit's value is transferred back to cell.


This event occurs even if edit wasn't successful (Accept parameter is set to False inside OnAcceptEdit event).

See also