PRODUCTS

FEATURED PRODUCT

With one subscription at over 50% discount price, you receive all current and future TMS VCL products + updates + support for 2 years

License only 695 EUR See More

SEARCH

LOGIN

Customer login to access products, support information & special benefits.

NEWS ALERTS

Add your e-mail address here to receive the monthly TMS Software alerts.

 

LINKS

EXAMPLE 48

TAdvStringGrid

example 48 : disjunct cell selection

Some new properties enable easy disjunct cell selections in TAdvStringGrid. The methods and properties to be used for this are :

Grid.MouseActions.DisjunctCellSelect: Boolean; Setting this true enables disjunct cell selection with Ctrl mouse clicks

Grid.SelectedCells[col,row: Integer]: Boolean; Property to allow setting or clearing selection on a single cell

Grid.SelectedCellsCount: Integer; Returns the number of disjunct selected cells (read-only)

Grid.SelectedCell[i: Integer]: TGridCoord; Returns the i'th selected cell grid coordinates (read-only)

Grid.ClearSelectedCells; Clears all disjunct selected cells in the grid

With this interface, handling disjunct cell selections becomes very simple as the sample app shows.

To make a checkerboard disjunct cell selection, following code was written:

var
  i,j: Integer;
begin
  AdvStringGrid1.ClearSelectedCells;
  with AdvStringGrid1 do
    for i := 1 to ColCount - 1 do
      for j := 1 to RowCount - 1 do
        SelectedCells[i,j] := (odd(i) and odd(j)) or (not odd(i) and not odd(j));
end;

This is the method to show a list of selected cells in a listbox:

var
  i: Integer;
  gc: TGridCoord;
begin
  listbox1.Items.Clear;
  listbox1.Items.Add('Nr. of cells : ' + IntToStr(AdvStringGrid1.SelectedCellsCount));
  for i := 1 to AdvStringGrid1.SelectedCellsCount do
  begin
    gc := AdvStringGrid1.SelectedCell[i - 1];
    listbox1.Items.Add(IntToStr(gc.X)+':'+IntToStr(gc.Y));
  end;
end;


Delphi project & source files for downloading included in the main demos distribution for Delphi.

The project and source files have been written with Delphi 6,7. To use these files in other versions of Delphi, ignore any remarks when opening the form files and save the files. After this, compilation can be done. The error messages are due to properties included in the Delphi 6 form file, but not available in lower versions of Delphi.  

Copyright © 1995 - 2008 TMS Software