Priyatna Codes - My Programming Journey
 


You are here: Home Delphi Stuffs NiceGrid
NiceGrid Component

Version: 2.20
Release Date: November 2nd, 2003

Introduction

NiceGrid is a free Delphi component that aimed to be a standard string grid replacement. It is written from scratch, not descended from TStringGrid. The main reason why I write this component is to have a grid component that nice and smooth. Here's some feature of NiceGrid:
  • Headers can be merged and or multilined.
  • Smooth scrolling, not aligned to top left cell coordinate.
  • All aspect of grid colors can be customized: header light color, header dark color, header color, grid color, text color, etc.; resulting a real nice looking grid.
  • Alternate row color.
  • Can be customized at design time.
  • Each column can have its own horizontal and vertical alignment, color, and font.
  • Each column can be hidden.
  • Can be auto fit to width.
  • Can be auto calculate column width.
  • BeginUpdate and EndUpdate method for bulk cells access.

Since it is a new component, there are several main differences between NiceGrid and TStringGrid:

  • Headers are excluded from cells, unlike TStringGrid that treats fixed rows as regular cells (Row 0, for example), Cells[0,0] in NiceGrid will access the top left editable cells, not fixed cell.

  • The only way to access the data is using Cells property or using direct array referencing style: NiceGrid1[0,0]. There are not (yet) Cols, or Rows property.

  • FixedRows -> Header, FixedCols -> Gutter.

Although this component is last released in 2003, it's a fresh code. I'm just lost track on what I modified between 2004 and 2007. :))

 

 

 

License

This library is released under Mozilla Public License. You can use it in your freeware, shareware or commercial softwares. You can send your modification to me, and if I decide to include it in the main distribution, I will add your name as a contributor. You can read full licensing information here.

 

 

Version History

Version 2.20

  • Bug fixed: OnCellChange event and friends only fired by user input, not by code (It seems that this behavior conforms with VCL design. I just get the point. ;-)

  • Bug fixed: messing up with accelerator keys. NiceGrid can't capture chars that already defined as accelerators of other control. This is fixed now.

  • C++ Builder port by C. S. Phua <csphua@teledynamics.com.my>.

Version 2.10

  • Problems in clipboard operations with some hidden columns, fixed.

  • OnAddRow event added, makes possible to set default values to new added row.

  • DeleteRow method added.

  • CanResize property in Column, this will control column width when FitToWidth property is set.

  • Some drawing enhachements.

Version 2.00

  • Bitmap buffering is removed. Believe me, this is not as easy as I thought.

  • Lot of enhanchement in editing capabilities and clipboard operations, most of them are adapted from well-known Microsoft Excel™.

  • Headers Title is more flexible now. It doesn't have to be complete. Just remember two basic rules: ';' for multiline and '|' for each header cell. Header and gutter have their own font.

  • Fill Down and Fill Right feature. This feature is actually created for my own purpose, but I think it's not a bad idea. To fill down a column, try to type something and then end with '*' and press ENTER. To fill right a row, use '>'.

  • Each column can be hidden. But use this feature wisely, because paste operation (from clipboard) will be applied also to hidden columns. It may make confuse end-user. I'll try to patch this later.

  • Cell editing can be done at design time via Column.Strings property.

  • Filter, Validation and Notification features: OnFilterChar, OnValidate, OnCellChanging, OnCellChange events; also EnableValidation - DisableValidation methods.

 

Installation

There is no special process to install it on Delphi. Just open NiceGridD7.dpk on Delphi IDE and press Install button. I use Delphi 7. If you use another Delphi version, you may have to make some minor changes.

The component will appear in priyatna.org tab.

 

Working with Headers

All features explained below are available at design time, but I will cover it using codes, for easy following.

NiceGrid will automatically scan column title and make appropriate merging and multilining. The only thing you must do is setting each column's Title property. This is a string type property. To make a multilined caption, use ';' (semicolon) character.

For example:

NiceGrid1.Columns[0].Title := 'First Line;Second Line';

will make

First Line
Second Line

 

HeaderLine property determines how much line will be allocated for headers. Each line in headers can be set also via column's Title property, separated by '|' character.

For example:

NiceGrid1.HeaderLine := 2;
NiceGrid1.Columns[0].Title := 'First Line|Second Line';

will make

First Line
Second Line

 

To merge two header cells, set each cell to exactly same value, including ';' characters if they are multilined.

For example:

NiceGrid1.HeaderLine := 2;
NiceGrid1.ColCount := 2;
NiceGrid1.Columns[0].Title := 'One|Two';
NiceGrid1.Columns[1].Title := 'One|Three';

will make

One
Two
Three

 

Using combination of '|' and ';' characters, we can make a complex header.

For example:

NiceGrid1.HeaderLine := 2;
NiceGrid1.ColCount := 5;
NiceGrid1.Columns[0].Title := 'Merged;Multilined|Merged;Multilined';
NiceGrid1.Columns[1].Title := 'First Group|One';
NiceGrid1.Columns[2].Title := 'First Group|Two';
NiceGrid1.Columns[3].Title := 'Second Group|Three';
NiceGrid1.Columns[4].Title := 'Second Group|Four';

will make

Merged
Multilined
First Group
Second Group
One
Two
Three
Four

 

Download

Download full source code and demo here:

NiceGrid.zip
737 KB

Version: 2.20
Release Date: November 2nd, 2003