Solved

how to insert button in string grid

Posted on 2003-11-12
3
2,248 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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now