I am thinking to right click on the title of a normal DBGrid to show a PopUp and select predefined filters.In the DbGrid OnMouseDown hancler you can call zone := grid.MouseToRecordOffset(x, y, column, offset); if the returned column is not nil you can use it to show the right popup menu. If you want to be sure you clicked a column header check the zone return value.
I have tried selecting Columns with GetMem code:But it is not functional because it identify the columns by id and not the name so if the user move the columns position it will not work fine.
procedure TForm2.DBGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var ACol, ARow: Integer; begin if Y < DBGrid1.DefaultRowHeight then begin (Sender as TDBGrid).MouseToCell(X, Y, ACol, ARow); if Button = mbRight then begin if DBGrid1.SelectedColumn.FieldName = 'Title1' then BEGIN ShowMessage('Title1'+ IntToStr(ACol)); end; if DBGrid1.SelectedColumn.FieldName = 'Title2' then BEGIN ShowMessage('Title2'+ IntToStr(ACol)); end; end; end; end;
The result for each column is "Title1" + column positiong id.