Jump to content
Vandrovnik

tDrawGrid - how to prevent OnDblClick on certain columns

Recommended Posts

Hello,

 

I have a DrawGrid, on some columns user can click to switch between values (enable / disable them). Is it possible to allow OnDblClick on some columns, while not allowing OnDblClick on these columns with "switches"? OnDblClick is used to open modal dialog to change some values.

Thank you, kind regards,

 

Karel

 

Share this post


Link to post
Posted (edited)

Double-click happens higher up in the inheritance chain of controls which means it does not consider the intended control's properties or functionalities because those don't exists where Double-Click originally is handled. This means you cannot prevent a Double-Click from happening just as is via any event. You have to intervene in another way

 

Fortunately DrawGird has public properties and methoss that can make it easier for you to decide whether you want to do something in OnDblClick for only certain columns, rows or cells. So you will check where the double-click took place and then only act when it fits the criteria.

 

One would think to look at DrawGrid.Row and DrawGrid.Col. They are set before Double-click and you can read them to get the cell where the click took place. The problem with them is when you click outside the cell range, a blank space in the grid for instance, then the last cell that was set will be given to you instead of the expected (-1,-1) coordinates. So you can look at DrawGrid.MouseToCell which will translate the mouse cursor position into the cell underneath the mouse cursor. Keep in mind MouseToCell takes Grid-relative cursor position as input. Thus you will have the cell that was underneath the cursor and now you can decide whether you wanna act or not.

 

Edited by PeaShooter_OMO

Share this post


Link to post
21 minutes ago, PeaShooter_OMO said:

One would think to look at DrawGrid.Row and DrawGrid.Col. They are set before Double-click and you can read them to get the cell where the click took place. The problem with them is when you click outside the cell range, a blank space in the grid for instance, then the last cell that was set will be given to you instead of the expected (-1,-1) coordinates. So you can look at DrawGrid.MouseToCell which will translate the mouse cursor position into the cell underneath the mouse cursor. Keep in mind MouseToCell takes Grid-relative cursor position as input. Thus you will have the cell that was underneath the cursor and now you can decide whether you wanna act or not.

 

Thank you for your reply. I did not write, that in this grid, RowSelet is set, so in OnDblClick I get Col=0.

So instead I used:

 var Cell: TGridCoord;
     Pt: tPoint;
 begin
 fSkipDrag:=true;
 Pt:=Mouse.CursorPos;
 Pt:=Grid.ScreenToClient(Pt);
 Cell:=Grid.MouseCoord(Pt.x, Pt.y);
 if (Cell.X<1) or (Cell.X>3) then ...

It is not perfect - if computer is really busy / slow, mouse may move before OnDblClick is run.

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

×