Documents

NextGrid & NextDBGrid

NextGrid

NextDBGrid

NextInspector

NextSheet

NextCollection

Misc

Labs

NextGrid .NET

InputLine Tutorial

Related Articles:

Info
  • Skill:
  • Version: 1.0.0
  • Author: Bojan Nikolic
  • Created: 2008-05-21
  • Updated: 2008-05-22
Input line special line on bellow grid header specially designed for adding new rows easily.

User may fill input cells and go trough then (with TAB key or mouse), and then by pressing Enter (or by clicking inside grid body) one new row will be added.

1. Enabling Input Line



Input line may be turned on by setting flag goInputLine in Options property of grid to True.

Input line also may be shown by right-click on component and choosing "Show Input Line" from pop-up menu.

New row may be added after pressing Enter key, or by clicking by mouse somewhere inside grid body.

If row is added by Enter, this may be additionally controlled by specifying InputEnterMode property.



2. Setting Input Line



Height of Input Line may be specified by InputSize property. Default value for this property is 16.

How Input Line will react when Enter key is pressed, may be specified by InputEnterMode property.

Table 1: InputEnterMode values
Name Meaning
imAllways New row will be added if InputLine is selected whenever input cell is in editing mode.
imEdit Default. New row will be added only if one of input cell is in editing mode.


Property WantReturns must be set to True in order to imAllways work.

3. Setting Columns



Every column may show custom caption (in gray font) in own cell within Input Line. This is specified by ItemCaption property.

For example, value of this property may be: "click here to add new row" or similar.



This text automatically becomes hidden when user start editing this input cell.

Text entered in input cell is stored into InputValue property. This property may be readed in events such as OnInputAccept and decided about adding new row or not.

If input within some column need to be disabled, coCanInput flag in Options property need to be set to False.

4. Input Line Events



OnInputAccept - This event occur before new row is added, and here may be decided whenever to accept or cancel adding of new row.

Accept parameter - Specify whenever grid will accept new row. Good practice is to run trough all columns and inspect InputValue property. Then to set Accept parameter to True or False.

Example showing how to not accept empty rows:

procedure TForm1.NextGrid1InputAccept(Sender: TObject;
  var Accept: Boolean);
var
  i: Integer;
begin
  Accept := False;
  for i := 0 to NextGrid1.Columns.Count - 1
  begin
    if NextGrid1.Columns[i].InputValue <> '' then
    begin
      Accept := True;
      Exit;
    end;
  end;
end;


OnInputAdded - This event occur after new row is added from InputLine. This event may be suitable for additional operations such as selecting newly added row:

procedure TForm1.NextGrid1InputAdded(Sender: TObject);
begin
  NextGrid1.SelectedRow := NextGrid1.LastAddedRow;
end;

Was This Article Useful?

Only constructive comments, code contributions... will be publishes. Questions, non-official discussion will not be published.