Question

I'd like to identify the screen coordinates of the Title cell which was clicked on the TDBGrid event TitleClick(Column: TColumn).

I can use the ColWidths property (exposed via a TDBGrid = class(DBGrids.TDBGrid) type declaration) but I am having difficulty in determining if the columns have been re-ordered by the user, combined with horizontal scrolling of the TDBGrid. I'd also like to keep track of where this Column is during subsequent moves and resizings, noting also that it's possible this column can be scrolled off the grid.

I've spent a long while on this problem and I am rather good at Delphi so this is not an idle question.

Was it helpful?

Solution

Using the trick in How do I get screen coordinates of the DBGrid cell, I wrote:

type
...
  THackedGrid = class(TDBGrid);
...
implementation
...
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
  currRow : Integer;
  rect : TRect;
begin
  currRow := THackedGrid(DBGrid1).Row;
  rect := THackedGrid(DBGrid1).CellRect(Column.Index+1,currRow);
end;

Is this what you want? The coordinate in rect is relative to the grid.

OTHER TIPS

I started working on a very similar grid yesterday at work. I am overlaying a control on the grid fixed row as you mentioned, activating it on a right click. This is what I doing so far, then setting the filter on my dataset. I have issues however when using multiselect on the combo. I would be very interested in seeing what you have accomplished since the last post.

procedure Tf_well.dbWellGridMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
var cell  : TGridCoord;
begin
    if Button = mbRight then
    begin
        Cell := dbWellGrid.MouseCoord(X, Y);
        //  showmessage(dbWellGrid.Columns[Cell.X-1].DisplayName);

        case Cell.X-1 of
            0:  begin
                    fieldComboWellName.Visible:=True;
                    fieldComboWellName.DroppedDown:=True;
                    fieldComboWellName.SetFocus;
                end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top