Solved

dgIndicator click event of dbGrid, Delphi7

Posted on 2008-06-20
4
1,208 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 107
Convert a string into a TDateTime 5 63
Base1 Encode/Decode 3 81
DBGrid or StringGrid ? 6 103
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

791 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