PRODUCTS

FEATURED PRODUCT

Office 2007 ribbon bar or Office 2003 toolbar & menus for your Windows applications

License only 75 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 62

TAdvStringGrid

example 62 : Checkbox based disjunct row selection

With this sample project, it is demonstrated how the checkboxes can be used to perform a disjunct row selection in the grid. This is done by adding a column of checkboxes in the grid and from the checkbox click event control the disjunct row selection state of the rows clicked.

The grid is initialized with the code:

var
  i: integer;
begin
  advstringgrid1.FixedCols := 0;
  advstringgrid1.ColWidths[0] := 20;
  advstringgrid1.Options := advstringgrid1.Options + [goRowSelect, goEditing];
  advstringgrid1.RowCount := 20;
  advstringgrid1.ShowSelection := false;
  for i := 1 to advstringgrid1.RowCount -1 do
    advstringgrid1.AddCheckBox(0,i,false,false);
  advstringgrid1.RandomFill(false,100);
end;

This code adds a checkbox in the first column for every row in the grid.

To let the row selection state reflect the checkbox state, the OnCheckBoxClick is implemented as:

procedure TForm1.AdvStringGrid1CheckBoxClick(Sender: TObject; ACol,
  ARow: Integer; State: Boolean);
begin
  advstringgrid1.RowSelect[Arow] := State;
end;

Finally, to obtain all selected rows and possibly perform some processing on these rows, this is done with:

var
  i: Integer;
  state: boolean;
begin
  Listbox1.Items.Clear;

  for i := 1 to AdvStringGrid1.RowCount - 1 do
  begin
    if Advstringgrid1.GetCheckBoxState(0,i,state) then
    begin
      if state then
      begin
        AdvStringGrid1.SetCheckBoxState(0,i,false);
        ListBox1.Items.Add(AdvStringgrid1.Cells[1,i]);
      end;
    end;
  end;
  if listbox1.Items.Count = 0 then
    ShowMessage('No items selected');
  AdvStringGrid1.Invalidate;
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