Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dgIndicator click event of dbGrid, Delphi7

Posted on 2008-06-20
4
Medium Priority
?
1,299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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 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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

715 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