Tom
Tom

Reputation: 575

Detect click in gutter (left margin) of TDbGrid?

I have a descendant of a TDBGrid that allows multiple rows to be selected.

I'd like to turn this mode on when they click in the gutter, and off when they click in any cell in the grid.

Is there a way in in the OnMouseDown event handler I can detect where they're clicking?

Upvotes: 2

Views: 534

Answers (1)

Ken White
Ken White

Reputation: 125669

OnMouseDown is difficult; you can get the coordinates via the X and Y parameters to the event, and convert to a row and column by typecasting the TDBGrid to it's ancestor TCustomGrid:

var
  Coord: TGridCoord;
begin
  Coord := TCustomGrid(DBGrid1).MouseCoord(X, Y);
  if Coord.X = 0 then
    // We're in the "gutter"
end;

However, it seems that OnMouseDown only fires for TDBGrid when the header row is clicked.

OnCellClick seems like a possible alternative, but it only fires on actual cells (excluding the gutter and header row), so it won't work. Neither will OnColEnter, as it doesn't fire when you'd want it to either.

It looks like your best option would be to use the standard Ctrl and Shift modifiers with the left mouse button to do your multiple selections, like every other app in Windows that does multi-select.

Upvotes: 2

Related Questions