Solved

how to insert button in string grid

Posted on 2003-11-12
3
2,539 Views
Last Modified: 2010-04-05
hi
      iam using delphi7 with ado2.1.iam using string grid in my form.i want to insert button in string grid.like when i click any row of a particular column a button should be visible.to be more precise say if i have four columns i want a button to be visible in second column when i click a row of that column


thanx
abu
0
Comment
Question by:abunectar
3 Comments
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 50 total points
ID: 9738815
Here an example....

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, Buttons, StdCtrls;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    btn: TButton;
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure btnClick(Sender: TObject);
    private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  col, Row: Integer;
implementation

{$R *.dfm}
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
sel: TRect;
begin
If Acol = 2 then begin
      Sel := StringGrid1.CellRect(Acol, Arow);
      SetWindowPos(btn.Handle, { handle }
              0,
              (StringGrid1.Left + 1) + ((Sel.Right )- (sel.Bottom-sel.Top)),
              Sel.Top + StringGrid1.top + 2,
              (sel.Bottom-sel.Top),
              Sel.Bottom - Sel.top ,
              SWP_NOZORDER or SWP_SHOWWINDOW);
      col := ACol;
      Row := ARow;
      btn.Show;
   end else btn.Hide;
end;

procedure TForm1.btnClick(Sender: TObject);
begin
 SHowMessage('Selected Row '+IntToSTr(Row)+ ' in Column '+IntToSTr(Col));
end;

end.

F68 ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question