I have to think there is some combination of options I must set and event handlers to hook to do what I need. But at this point it is eluding me.
Hi Martel,
Daniele,
//Private form variables
Hi Martel,
i search in my old project and fount it !!!!
I have isolated a piece of code that do what you search .... it work at 90% ... the last 10% is your headache eheheheh.
Limit ... it's work with delphi Seattle and old Component pack (because i'm on that pc) with advstringlist (not latest version).
Here the unit
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvUtil, Vcl.Grids, AdvObj, BaseGrid,
AdvGrid, Vcl.StdCtrls;
type
TForm1 = class(TForm)
SG1: TAdvStringGrid;
procedure FormCreate(Sender: TObject);
procedure SG1ClickCell(Sender: TObject; ARow, ACol: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
Var I : Byte;
begin
SG1.ClearAll;
SG1.ColCount:=6;
SG1.RowCount:=1;
for I:=1 to 50 Do
Begin
SG1.AddRow;
SG1.Ints[1,I]:=I;
SG1.AddCheckBox(2,I,False,False);
End;
end;
procedure TForm1.SG1ClickCell(Sender: TObject; ARow, ACol: Integer);
Var state : Boolean;
I : Integer;
SL : TStringList;
begin
if ACol=2 then
begin
SL:=TStringList.Create;
for i := 0 to SG1.SelectedRowCount - 1 do
Begin
// Copy selected row index
SL.Add(IntToStr(SG1.SelectedRow));
End;
if SG1.GetCheckBoxState(ACol,Arow,State) then SG1.SetCheckBoxState(ACol,ARow, Not state);
for I:=0 to SL.Count-1 do
begin
SG1.RowSelect[StrToint(SL)]:=True;
SG1.SetCheckBoxState(ACol,StrToint(SL), Not state);
End;
FreeAndNil(SL);
end;
end;
end.
Setting: in order to work (90%) please set in grid option
goRowSelect:=True
and in mouseAction
DisjunctRowSelect:=True
In this scenario, you can check/uncheck any selected row on it's checkbox and the state is applyed to all each other rows.
Why work only 90%?
Because the row where you click change the selected status ..... but with e few code lines i'm sure you can fix this and made it selectable ...
To save your time ... i'm adjust the above to the follow one and now work 100%
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvUtil, Vcl.Grids, AdvObj, BaseGrid,
AdvGrid, Vcl.StdCtrls;
type
TForm1 = class(TForm)
SG1: TAdvStringGrid;
procedure FormCreate(Sender: TObject);
procedure SG1ClickCell(Sender: TObject; ARow, ACol: Integer);
procedure SG1CheckBoxMouseUp(Sender: TObject; ACol, ARow: Integer;
State: Boolean);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
SL : TStringList;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FreeAndNil(SL);
end;
procedure TForm1.FormCreate(Sender: TObject);
Var I : Byte;
begin
SL:=TStringlist.Create;
SG1.ClearAll;
SG1.ColCount:=6;
SG1.RowCount:=1;
for I:=1 to 50 Do
Begin
SG1.AddRow;
SG1.Ints[1,I]:=I;
SG1.AddCheckBox(2,I,False,False);
End;
end;
procedure TForm1.SG1CheckBoxMouseUp(Sender: TObject; ACol, ARow: Integer;
State: Boolean);
begin
if SL.IndexOf(IntToStr(ARow))<>-1 then
Begin
SG1.RowSelect[Arow]:=True;
End;
end;
procedure TForm1.SG1ClickCell(Sender: TObject; ARow, ACol: Integer);
Var state : Boolean;
I : Integer;
begin
if ACol=2 then
begin
SL.Clear;
for i := 0 to SG1.SelectedRowCount - 1 do
Begin
// Copy selected row index
SL.Add(IntToStr(SG1.SelectedRow));
End;
if SG1.GetCheckBoxState(ACol,Arow,State) then SG1.SetCheckBoxState(ACol,ARow, Not state);
for I:=0 to SL.Count-1 do
begin
SG1.RowSelect[StrToint(SL)]:=True;
SG1.SetCheckBoxState(ACol,StrToint(SL), Not state);
End;
end;
end;
end.
As you know well be aware about keyboard/mouse action because you can loose all your selected row if you release the crtl key.
I'm sure this code will be improved, but i'm hope this can help you and be a starting point.
Regard
Daniele
Daniele,
Hi Martel,
you're rigth !!!
Now i'm on my house pc with delphi rio.
There are some errors .... due to unknow reason (i'm just copy the code into the forum).
Anyway, i'm glad you have already solved the problem but, only to fix the above code, here the all little project full running on rio
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvUtil, Vcl.Grids, AdvObj, BaseGrid,
AdvGrid, Vcl.StdCtrls;
type
TForm1 = class(TForm)
SG1: TAdvStringGrid;
procedure FormCreate(Sender: TObject);
procedure SG1ClickCell(Sender: TObject; ARow, ACol: Integer);
procedure SG1CheckBoxMouseUp(Sender: TObject; ACol, ARow: Integer;
State: Boolean);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
SL : TStringList;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FreeAndNil(SL);
end;
procedure TForm1.FormCreate(Sender: TObject);
Var I : Byte;
begin
SL:=TStringlist.Create;
SG1.ClearAll;
SG1.ColCount:=6;
SG1.RowCount:=1;
for I:=1 to 50 Do
Begin
SG1.AddRow;
SG1.Ints[1,I]:=I;
SG1.AddCheckBox(2,I,False,False);
End;
end;
procedure TForm1.SG1CheckBoxMouseUp(Sender: TObject; ACol, ARow: Integer;
State: Boolean);
var I : Integer;
begin
if SL.IndexOf(IntToStr(ARow))<>-1 then
Begin
SG1.RowSelect[Arow]:=True;
End;
end;
procedure TForm1.SG1ClickCell(Sender: TObject; ARow, ACol: Integer);
Var state : Boolean;
I : Integer;
begin
if ACol=2 then
begin
SL.Clear;
for i := 0 to SG1.SelectedRowCount - 1 do
Begin
// Copy selected row index
SL.Add(IntToStr(SG1.SelectedRow));
End;
if SG1.GetCheckBoxState(ACol,Arow,State) then SG1.SetCheckBoxState(ACol,ARow, Not state);
for I:=0 to SL.Count-1 do
begin
SG1.RowSelect[StrToint(SL)]:=True;
SG1.SetCheckBoxState(ACol,StrToint(SL), Not state);
End;
end;
end;
end.
I think that working on internal row indexs (RowSelect and SelectedRow) is possible delete the stringlist variable.
As said before, this just for “errata corrige”
Excuse me for any inconvenients.
Regards
Daniele
Hi,
Martel,
Please just stop replying. It is not needed and will confuse the whole topic.