Solved

dgIndicator click event of dbGrid, Delphi7

Posted on 2008-06-20
4
1,197 Views
Last Modified: 2012-06-21
Hello Experts,
I have a question regarding DBGrid.
How do i capture the event of dgIndicator click.
OnCellClick event exists but is there any method to find out the event of dgIndicator click.

Thanks
0
Comment
Question by:Asmitagoyal
  • 2
  • 2
4 Comments
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 75 total points
ID: 21829989
looks like you'll have to alter the MouseUp procedure in a DBGrid descendent

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, DBAccess, Ora, MemDS;

type
  TIndicatorClickEvent = procedure (Sender: TObject; ARow: Integer) of object;

  TMyDBGrid = class(TDBGrid)
  private
    FOnIndicatorClick: TIndicatorClickEvent;
  protected
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure IndicatorClick(ARow: Integer); dynamic;
  published
    property OnIndicatorClick: TIndicatorClickEvent read FOnIndicatorClick write FOnIndicatorClick;
  end;

  TForm1 = class(TForm)
    DBGrid: TDBGrid;
    ds: TDataSource;
    OraQuery: TOraQuery;
    OraSession: TOraSession;
    procedure FormCreate(Sender: TObject);
  private
    procedure dgIndicator(Sender: TObject; ARow: Integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TMyDBGrid }

procedure TMyDBGrid.IndicatorClick(ARow: Integer);
begin
  if Assigned(FOnIndicatorClick) then
    FOnIndicatorClick(Self, ARow);
end;

procedure TMyDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Cell: TGridCoord;
  SaveState: TGridState;
  FirstCell: TRect;
begin
  SaveState := FGridState;
  inherited MouseUp(Button, Shift, X, Y);
  if (SaveState = gsRowSizing) or (SaveState = gsColSizing) or
    ((InplaceEditor <> nil) and (InplaceEditor.Visible) and
     (PtInRect(InplaceEditor.BoundsRect, Point(X,Y)))) then Exit;
  FirstCell := CellRect(1, 1);
  Cell := MouseCoord(X,Y);
  if (Button = mbLeft) and (X <= IndicatorWidth) and (Y >= FirstCell.Top) then
    IndicatorClick(Cell.Y);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with TMyDBGrid.Create(Self) do
  begin
    Parent := Self;
    OnIndicatorClick := dgIndicator;
    DataSource := ds;
  end;
end;

procedure TForm1.dgIndicator(Sender: TObject; ARow: Integer);
begin
  ShowMessage('Row indicator: ' + IntToStr(ARow));
end;

end.
0
 
LVL 10

Expert Comment

by:dinilud
ID: 21830884
For discussion

procedure TMyDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Cell: TGridCoord;
  SaveState: TGridState;
  //FirstCell: TRect;
begin
  SaveState := FGridState;
  inherited MouseUp(Button, Shift, X, Y);
  if (SaveState = gsRowSizing) or (SaveState = gsColSizing) or
    ((InplaceEditor <> nil) and (InplaceEditor.Visible) and
     (PtInRect(InplaceEditor.BoundsRect, Point(X,Y)))) then Exit;
  //FirstCell := CellRect(1, 1);
  Cell := MouseCoord(X,Y);
  if (Button = mbLeft) and (dgIndicator in Options) and (X <= IndicatorWidth) then
  begin
     if (dgTitles in Options) and (Cell.Y > 0) then exit;
     IndicatorClick(Cell.Y);
  end;
end;



................
................


  with TMyDBGrid.Create(Self) do
  begin
    Parent := Self;
    Options:=Options-[dgTitles];
    OnIndicatorClick := dgIndicator;
    DataSource := DataSource1 ;
  end;
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21830916
a B for this solution ?
And what didn't work ?
0
 
LVL 10

Expert Comment

by:dinilud
ID: 21831002
While i am studing your answer i found
   if title not exist,it gives wrong answer. thats all.
this is not for irritating you.


with TMyDBGrid.Create(Self) do
  begin
    Parent := Self;
    Options:=Options-[dgTitles];
    OnIndicatorClick := dgIndicator;
    DataSource := DataSource1 ;
  end;
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 303
SUM 2 INTEGER ARRAYS INTO 1 10 100
JAudiorecorder record freezing the app 29 67
PHP preg_replace code convert to Delphi 14 55
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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