Forum > Databases

Create something right clicking DBGrid column titles

<< < (2/2)

jesusr:

--- Quote from: Heinz on October 18, 2021, 05:20:59 pm ---I am thinking to right click on the title of a normal DBGrid to show a PopUp and select predefined filters.
I have tried selecting Columns with GetMem code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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; 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.
The result for each column is "Title1" + column positiong id.

--- End quote ---
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.

Heinz:
Thank you

Navigation

[0] Message Index

[*] Previous page

Go to full version