Jump to content
Sign in to follow this  
Henry Olive

PopUpMenu TPoint

Recommended Posts

I wish everyone a healthy day.
 

I want to Filter a Dataset 

When user click the DBGrid's *desired title (Column)* i want to show a PopUpMenu

according to its place in the dbgrid's column

I write below code

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
  var
  p:TPoint;
begin
  if Column.FieldName ='TNAME' then

    p:=DBGrid1.ClientToScreen(Point(0,DBGrid1.Height));
    Pop1.Popup(p.x, p.y)

end;

With above code PopUpMenu PopUp sometimes Above, sometimes below of the dbgrid

I need the PopUpMenu PopUp according to its place in the dbgrid's column

Something like below

  p:=DBGrid1.Columns[1].ClientToScreen(Point(0,DBGrid1.Columns[1].Height));


Thank You

 

Share this post


Link to post
1 hour ago, Henry Olive said:

I want to Filter a Dataset 

When user click the DBGrid's *desired title (Column)* i want to show a PopUpMenu

according to its place in the dbgrid's column

I write below code

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
  var
  p:TPoint;
begin
  if Column.FieldName ='TNAME' then

    p:=DBGrid1.ClientToScreen(Point(0,DBGrid1.Height));
    Pop1.Popup(p.x, p.y)

end;

With above code PopUpMenu PopUp sometimes Above, sometimes below of the dbgrid

I need the PopUpMenu PopUp according to its place in the dbgrid's column

Something like below

  p:=DBGrid1.Columns[1].ClientToScreen(Point(0,DBGrid1.Columns[1].Height));


Try this:


type
  TGridCracker = class(TDBGrid);


procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
  LPoint: TPoint;
  LRect: TRect;
begin
  LRect := TGridCracker(Column.Grid).CellRect(Column.Index+1, 0);
  LPoint := Column.Grid.ClientToScreen(LRect.TopLeft);
  LPoint.Y := LPoint.Y + TGridCracker(Column.Grid).RowHeights[0];
  PopupMenu1.Popup(LPoint.X, LPoint.Y);
end;

Unfortunately TDBGrid offers no easy way through public methods or properties to get at the screen coordinates of a cell, so one has to fall back to protected methods inherited from TCustomGrid. The advantage of CellREct is that iot also works correctly when the grid is scrolled horizontally.

 

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×