unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.Grids,
Vcl.StdCtrls;
type
TInlineCheckBox=class(TCheckBox)
public
Grid: TStringGrid;
Col: Integer;
Row: Integer;
end;
TForm1 =
class(TForm)
strngrd1: TStringGrid;
procedure FormShow(Sender: TObject);
procedure CheckboxClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CheckboxClick(Sender: TObject);
begin
if (Sender
as TInlineCheckBox).Checked
then
ShowMessage(Format('
Col: %d Row: %d',[(Sender
as TInlineCheckBox).Col,
(Sender
as TInlineCheckBox).Row]));
end;
procedure TForm1.FormShow(Sender: TObject);
var
c: Integer;
r: Integer;
InlineCheckBox: TInlineCheckBox;
begin
for c := 1
to strngrd1.ColCount-1
do
for r := 1
to strngrd1.RowCount-1
do
begin
InlineCheckBox:=TInlineCheckBox.Create(self);
InlineCheckBox.OnClick:=CheckboxClick;
InlineCheckBox.Parent:=strngrd1;
InlineCheckBox.Grid:=strngrd1;
InlineCheckBox.Col:=c;
InlineCheckBox.Row:=r;
InlineCheckBox.BoundsRect:=strngrd1.CellRect(c, r);
InlineCheckBox.Checked:=strngrd1.Cells[c, r]<>'
';
end;
end;
end.