Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

dgIndicator click event of dbGrid, Delphi7

Posted on 2008-06-20
4
Medium Priority
?
1,321 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 38

Accepted Solution

by:
Geert Gruwez earned 225 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 38

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

Technology Partners: 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses

971 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