Jump to content


Photo

Tips & Tricks

tips tricks nextgrid6

  • This topic is locked This topic is locked
7 replies to this topic

#1 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,901 posts
  • Gender:Male

Posted 05 April 2016 - 01:03 PM

Adding and customising column in code

After column is added, it can be easily configured (customised) with following techniques:

// 3rd parameter set ShortCaption property
with NextGrid61.Columns.Add(TNxTextColumn6, 'Number of Order', 'No') do
begin
  Alignment := taRightJustify;
  Width := 60;
end;
Or with handy LastAddedColumn (there is also LastAddedRow):
NextGrid61.Columns.Add(TNxTextColumn6, 'Number of Order', 'No');
NextGrid61.LastAddedColumn.Alignment := taRightJustify;
If you need to use properties which are not in base TNxColumn6 class returned by Add method, use typecasting:
with NextGrid61.Columns.Add(TNxNumberColumn6, 'Number of Order', 'No') as TNxNumberColumn6 do
begin
  // Still good
  Alignment := taRightJustify;
  Width := 60;
  // Only in TNxNumberColumn6
  Precision := 2;
  SpinButtons := False;
end;

boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,901 posts
  • Gender:Male

Posted 05 April 2016 - 01:13 PM

Preventing user to leave editing mode
 
With OnAcceptEdit User's entry can be further adjusted, or even rejected.
procedure TForm1.NextGrid61AcceptEdit(Sender: TObject; ACol, ARow: Integer; var Text: WideString;
  var Accept, CanLeave: Boolean);
begin
  if Length(Trim(Text)) < 3 then
  begin
    // Don't transfer value back to cell
    Accept := False;
 
    { Cell is still in editing mode,
      even if user try to select another cell. }
    CanLeave := False;
 
    // Replace User's entry with our value
    Text := 'default';
 
    // Alert user with sound
    Beep;
  end;
end;

boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,901 posts
  • Gender:Male

Posted 05 April 2016 - 01:20 PM

AddRow and IgnoreDefaults parameter
 
AddRow beside well known Count parameter include IgnoreDefaults optional parameter.

function AddRow(const Count: Integer = 1; IgnoreDefaults: Boolean = True): INxCellsRow; virtual;
If set to False value set in DefaultValue property of each column will be used while adding new row.
 
Example:
// DefaultValue for each column type is in Column's native type
NxTextColumn61.DefaultValue := 'Default Value';
NxNumberColumn61.DefaultValue := 5;
NxCheckBoxColumn61.DefaultValue := False;

// Finally, add row with last parameter set to False
NextGrid61.AddRow(1, False);
Remarks

This parameter is by default True since it's not suitable when adding several rows at once.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,901 posts
  • Gender:Male

Posted 05 April 2016 - 01:33 PM

Virtually setting value

Each column include very handy OnGetValue event.

This event is called every time Cell's value need to be used by Grid (for painting cell, for editing etc.)

For example, if actual stored value of cell is 5
NextGrid61.Cell[NxNumberColumn61.Index, 0].AsFloat := 5;
With this event, value presented to user will be 7:
procedure TForm1.NxNumberColumn61GetValue(Sender: TObject; ACol, ARow: Integer;
  var Value: Double);
begin
  Value := Value + 2;
end;
Each column include this event, but Value parameter is in column-native type:
procedure TForm1.NxCheckBoxColumn61GetValue(Sender: TObject; ACol, ARow: Integer; var Value: Boolean);
begin
  if ARow < 3 then Value := True;
end;
Beside this event, there is also OnGetText which provide opportunity to adjust text to be displayed on screen, and formatted by column. For example, numeric column will format underlaying Value with FormatMask.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,901 posts
  • Gender:Male

Posted 05 April 2016 - 01:41 PM

Quickly add cells with AddCells method

AddCells method add array of cells, but also add rows if needed.
 
In following example we are adding cells with values for columns with indexes: 0, 1, 2. Since there is enough data for another row, 2nd row will be also added and set.

NextGrid61.AddCells(['Abc', '1234.5', 'True', 'Efg', '0', 'False'], [0, 1, 2]);

One more example:

NextGrid61.AddCells([Edit1.Text, 'False'], [NxTextColumn61.Index, NxCheckBoxColumn61.Index]);

boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,901 posts
  • Gender:Male

Posted 05 April 2016 - 09:16 PM

Add row and quickly set it's cells
 
AddRow method return object of INxCellsRow type which represent newly added row.
 
This object have Cells property which then have Item[ColIndex] array of cells inside this row.

with NextGrid61.AddRow.Cells do
begin
  Item[0].AsString := Edit1.Text;
  Item[0].Color := clCream;
  Item[1].AsFloat := 0;
  Item[2].AsBoolean := CheckBox1.Checked;
  Item[2].Locked := True; // Lock cell for editing
end;

Same properties can be used for editing existing rows/cells:

with (NextGrid61.Row[NextGrid61.SelectedRow] as INxCellsRow).Cells do
begin
  Item[0].AsString := Edit1.Text;
  Item[2].AsBoolean := CheckBox1.Checked;
end;

Row property of Grid is INxRow type so we are using typecasting.
 
Why Row property doesn't return INxCellsRow instead of INxRow?
 
In future other kind of rows may be added (e.g. TNxGroupRow6). NextDBGrid also have own kind of rows (TNxRecordRow6). They are all have INxRow as "base" type.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#7 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,901 posts
  • Gender:Male

Posted 20 April 2016 - 01:57 AM

Searching for Text in Cells
 
FindText method search Grid for string specified by the Text parameter. Beside this parameter, you can specify FirstRow, EndRow and Columns's scope (array) to be searched.
 
Last 2 parameters are crucial and specify how value inside cells will be matched with parameter Text.
  • Options (TNxSearchMatchingOptions)
    set of (soCaseSensitive, soRestartAfterEnd, soIncludeInvisible
  • MatchingOptions (TNxSearchMatchingOptions)
    (moExactMatch, moBeginWith, moContain)
Example:
FoundIndex := NextGrid61.FindText(
  [NxTextColumn61.Index, NxTextColumn62.Index], // -> Column's Indexes
  Edit1.Text, // -> what to find
  StartIndex, // -> Usually SelectedRow
  NextGrid61.RowCount - 1,
  Options, // -> TNxSearchOptions
  MatchingOptions // -> TNxSearchMatchingOptions
);
This method set value for LastFoundRow, and return index of found row.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#8 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 7,901 posts
  • Gender:Male

Posted 10 June 2016 - 01:10 PM

Export to HTML

To export NextGrid6 into HTML file use non-visual NxGridHTMLExport6 component (that can be found in “Next Suite 6” category inside Components Palette).

First set Associate property to grid component:
 

NxGridHTMLExport61.Associate := MyGrid;

or in design-time.

Then call SaveToFile method of NxGridHTMLExport6 component.
 

NxGridHTMLExport61.SaveToFile('c:\tmp\laza.html');

This component offers some handy properties such as:

- Colors: Specifies color palette for grid lines, header.
- ImagesFolder: Specifies sub-folder for images. Icon and Graphic columns can be saved as image.
- StylesFileName: Specifies name of CSS file. Default styles.css.
- StylesFolder: Sub-folder for styles file.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: dn.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.





Also tagged with one or more of these keywords: tips, tricks, nextgrid6

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users