hi..
i want to check / uncheck all rows in grid by check head column's checkbox.
so i added checkbox in header
then i can't check it.(maybe it enabled)..
but in stringgrid, it is work.
how can I solve this problem..??
help me please..
this below is your demo source
{*************************************************************************}
{ TAdvStringGrid demo unit }
{ }
{ written by TMS Software }
{ copyright ?1998-2011 }
{ Email : info@tmssoftware.Com }
{ Web : http://www.tmssoftware.Com }
{ }
{ The source code is given as is. The author is not responsible }
{ for any possible damage done due to the use of this code. }
{ The component can be freely used in any application. The complete }
{ source code remains property of the author and may not be distributed, }
{ published, given or sold in any form as such. No parts of the source }
{ code can be included in any other component or application without }
{ written authorization of the author. }
{*************************************************************************}
unit Unit1;
{ TAdvStringGrid demo unit }
{ }
{ written by TMS Software }
{ copyright ?1998-2011 }
{ Email : info@tmssoftware.Com }
{ Web : http://www.tmssoftware.Com }
{ }
{ The source code is given as is. The author is not responsible }
{ for any possible damage done due to the use of this code. }
{ The component can be freely used in any application. The complete }
{ source code remains property of the author and may not be distributed, }
{ published, given or sold in any form as such. No parts of the source }
{ code can be included in any other component or application without }
{ written authorization of the author. }
{*************************************************************************}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, BaseGrid, AdvGrid, StdCtrls, XPMan, AdvObj, AdvCGrid;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, BaseGrid, AdvGrid, StdCtrls, XPMan, AdvObj, AdvCGrid;
type
TForm1 = class(TForm)
AdvStringGrid1: TAdvStringGrid;
Button1: TButton;
ListBox1: TListBox;
AdvColumnGrid1: TAdvColumnGrid;
procedure FormCreate(Sender: TObject);
procedure AdvStringGrid1CheckBoxClick(Sender: TObject; ACol,
ARow: Integer; State: Boolean);
procedure AdvStringGrid1CanEditCell(Sender: TObject; ARow,
ACol: Integer; var CanEdit: Boolean);
procedure AdvStringGrid1GetCellColor(Sender: TObject; ARow,
ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
procedure Button1Click(Sender: TObject);
procedure AdvStringGrid1CheckBoxChange(Sender: TObject; ACol,
ARow: Integer; State: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
TForm1 = class(TForm)
AdvStringGrid1: TAdvStringGrid;
Button1: TButton;
ListBox1: TListBox;
AdvColumnGrid1: TAdvColumnGrid;
procedure FormCreate(Sender: TObject);
procedure AdvStringGrid1CheckBoxClick(Sender: TObject; ACol,
ARow: Integer; State: Boolean);
procedure AdvStringGrid1CanEditCell(Sender: TObject; ARow,
ACol: Integer; var CanEdit: Boolean);
procedure AdvStringGrid1GetCellColor(Sender: TObject; ARow,
ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
procedure Button1Click(Sender: TObject);
procedure AdvStringGrid1CheckBoxChange(Sender: TObject; ACol,
ARow: Integer; State: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
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 := 0 to advstringgrid1.RowCount - 1 do
advstringgrid1.AddCheckBox(0, i, false, false);
advstringgrid1.RandomFill(false, 100);
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 := 0 to advstringgrid1.RowCount - 1 do
advstringgrid1.AddCheckBox(0, i, false, false);
advstringgrid1.RandomFill(false, 100);
AdvColumnGrid1.FixedCols := 0;
AdvColumnGrid1.ColWidths[0] := 20;
AdvColumnGrid1.Options := advstringgrid1.Options + [goRowSelect, goEditing];
AdvColumnGrid1.RowCount := 20;
AdvColumnGrid1.ShowSelection := false;
for i := 0 to AdvColumnGrid1.RowCount - 1 do
AdvColumnGrid1.AddCheckBox(0, i, false, false);
AdvColumnGrid1.RandomFill(false, 100);
AdvColumnGrid1.ColWidths[0] := 20;
AdvColumnGrid1.Options := advstringgrid1.Options + [goRowSelect, goEditing];
AdvColumnGrid1.RowCount := 20;
AdvColumnGrid1.ShowSelection := false;
for i := 0 to AdvColumnGrid1.RowCount - 1 do
AdvColumnGrid1.AddCheckBox(0, i, false, false);
AdvColumnGrid1.RandomFill(false, 100);
end;
procedure TForm1.AdvStringGrid1CheckBoxClick(Sender: TObject; ACol,
ARow: Integer; State: Boolean);
begin
advstringgrid1.RowSelect[Arow] := State;
ARow: Integer; State: Boolean);
begin
advstringgrid1.RowSelect[Arow] := State;
end;
procedure TForm1.AdvStringGrid1CanEditCell(Sender: TObject; ARow,
ACol: Integer; var CanEdit: Boolean);
begin
CanEdit := ACol = 0;
end;
ACol: Integer; var CanEdit: Boolean);
begin
CanEdit := ACol = 0;
end;
procedure TForm1.AdvStringGrid1GetCellColor(Sender: TObject; ARow,
ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
var
state: boolean;
begin
if AdvStringGrid1.GetCheckBoxState(0, ARow, state) then
begin
if state then
ABrush.Color := AdvStringGrid1.SelectionColor;
end;
end;
ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
var
state: boolean;
begin
if AdvStringGrid1.GetCheckBoxState(0, ARow, state) then
begin
if state then
ABrush.Color := AdvStringGrid1.SelectionColor;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
state: boolean;
begin
Listbox1.Items.Clear;
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;
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;
procedure TForm1.AdvStringGrid1CheckBoxChange(Sender: TObject; ACol,
ARow: Integer; State: Boolean);
begin
if ARow = 0 then begin
if AdvStringGrid1.GetCheckBoxState(0, ARow, State) then begin
if State = true then begin
AdvStringGrid1.CheckAll(0);
end else begin
AdvStringGrid1.UnCheckAll(0);
end;
end
end;
ARow: Integer; State: Boolean);
begin
if ARow = 0 then begin
if AdvStringGrid1.GetCheckBoxState(0, ARow, State) then begin
if State = true then begin
AdvStringGrid1.CheckAll(0);
end else begin
AdvStringGrid1.UnCheckAll(0);
end;
end
end;
end;
end.