Einzelnen Beitrag anzeigen

Benutzerbild von x000x
x000x

Registriert seit: 21. Jan 2004
Ort: Bei Hamburg
308 Beiträge
 
Delphi XE2 Professional
 
#2

Re: DBgrid + TitleClick + Rechte Maustaste

  Alt 13. Nov 2007, 20:25
Moin moin,
wirklich weiter helfen vielleicht nicht, aber einen Ansatz geben?!
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids;

type
  TMyDBGrid = class(TDBGrid)
  private
    FOnTitleRightClick: TDBGridClickEvent;
  protected
    procedure TitleRightClick(Column: TColumn); dynamic;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer); override;
    property OnTitleRightClick: TDBGridClickEvent read FOnTitleRightClick write FOnTitleRightClick;
  end;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    MyDBGrid1: TMyDBGrid;
    procedure MyTitleClick(Column: TColumn);
    procedure MyTitleRightClick(Column: TColumn);
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TMyDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer);
var
  Cell: TGridCoord;
begin
  inherited MouseUp(Button, Shift, X, Y);
  Cell := MouseCoord(X,Y);
  if (Button = mbright) and (Cell.X >= IndicatorOffset) and (Cell.Y = 0) then
    TitleRightClick(Columns[RawToDataColumn(Cell.X)]);
end;

procedure TMyDBGrid.TitleRightClick(Column: TColumn);
begin
  if Assigned(FOnTitleRightClick) then FOnTitleRightClick(Column);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyDBGrid1 := TMyDBGrid.Create(Self);
  MyDBGrid1.Parent := Self;
  with MyDBGrid1.Columns.Add do
    Title.Caption := 'Test1';
  with MyDBGrid1.Columns.Add do
    Title.Caption := 'Test2';
  MyDBGrid1.OnTitleClick := MyTitleClick;
  MyDBGrid1.OnTitleRightClick := MyTitleRightClick;
end;

procedure TForm1.MyTitleClick(Column: TColumn);
begin
  ShowMessage('Links - ' + Column.Title.Caption);
end;

procedure TForm1.MyTitleRightClick(Column: TColumn);
begin
  ShowMessage('Rechts - ' + Column.Title.Caption);
end;

end.
Peter
-= Gruss Peter =-
-= alias x000x =-
  Mit Zitat antworten Zitat