سلام،
می بخشید با تاخیر جواب میدم...
برای DBGrid مورد نظر یک ستون جدید تعریف بکنید مقدار ActionColIndex در کد زیر را بر روی شماره Index اون ستون تنظیم کنید:
const
ActionColIndex = 3;
type
THackedDBGrid = class(TDBGrid);
procedure TForm1.FormCreate(Sender: TObject);
begin
Button := TButton.Create(Self);
with Button do
begin
Parent := self;
Visible := False;
Caption := 'Do Action';
TabStop := True;
OnClick := GridActionBtnClick;
end;
end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
GridCurrentRow,
DbCurrentRow : integer;
begin
GridCurrentRow := THackedDBGrid(Sender).Row;
DbCurrentRow := AdoTable1.RecNo;
if DataCol = ActionColIndex then
if GridCurrentRow = DbCurrentRow then
begin
with Button do
begin
Left := Rect.Left + DBGrid1.Left + 2;
Top := Rect.Top + DBGrid1.top + 2;
Height := Rect.Bottom - Rect.Top;
Width := Rect.Right - Rect.Left;
Visible := True;
end;
end;
end;
procedure TForm1.GridActionBtnClick(Sender: TObject);
begin
ShowMessage('Button is clicked');
end;