Recent

Author Topic: Visible:=True seems to be Modal  (Read 2829 times)

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Visible:=True seems to be Modal
« on: January 22, 2017, 10:22:59 pm »
I have a DBGrid.Visable:=False; until a user clicks an Edit then it is set Visible in the Edit.OnEnter.

In the DBGrid.OnCellClick I use the user's-selection and set the grid invisible again. All works fine -- except -- if I click anywhere other than the DBGrid, none of the underlying components see the click. The only way I can get the grid to go invisible is clicking within it.

It's as if .Visible:=True means ShowModal instead of just Show

How can I get this to behave better. By the way, I just checked with Delphi and it works as expected and I can use the OnExit event of the DBGrid to hide it again when I click anywhere outside of the DBGrid.
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Visible:=True seems to be Modal
« Reply #1 on: January 23, 2017, 07:15:26 am »
IIt's as if .Visible:=True means ShowModal instead of just Show
You need to provide a way to process the paint messages. Otherwise the grid stays visible.
After you set DbGrid.Visible := false; call Application.ProcessMessages or call Form.Invalidate;
« Last Edit: January 23, 2017, 07:17:11 am by Thaddy »
Specialize a type, not a var.

derek.john.evans

  • Guest
Re: Visible:=True seems to be Modal
« Reply #2 on: January 23, 2017, 07:55:12 am »
So, when a cell is clicked, or the DBGrid looses focus, you want the DBGrid to hide? And, it wont hide unless you click on a cell?

That means your OnExit event isn't being called, which means the DBGrid isn't gaining the focus in the first place.

Try:
Code: Pascal  [Select][+][-]
  1.     DBGrid1.Visible := True;
  2.     DBGrid1.SetFocus;  
  3.  

Edit: I have tested this with Windows XP (Laz1.6.2).

Note: "when I click anywhere outside of the DBGrid" doesn't really explain what you mean. Anywhere must be something which will take focus from the DBGrid, for the OnExit to trigger. Otherwise, you have to manually use SetFocus or ActiveControl.
« Last Edit: January 23, 2017, 08:01:07 am by Geepster »

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: Visible:=True seems to be Modal
« Reply #3 on: January 23, 2017, 07:11:04 pm »
Thanks, but I may not have been clear enough as neither of those responses addresses the problem.
On the Main Form named "frmMain," and I have a secondary Form named "frmDatabase"
I have an Edit on frmDatabase.
I have a DBGrid on frmDatabase set with Visible:=False at runtime.
When the user clicks the Edit the Grid is made visible using Edit.OnEnter.
When the user clicks an item within the grid, the grid is then hidden using the OnCellClick and the selected Record data is displayed in the Edit.
All of that works as expected and intended.

But, when the grid is visible and I click anywhere on the underlying frmDatabase or frmMain, those clicks are not registered.

I have tried KeyPreview for the main form, OnMOuseDown/Up/Click etc., but nothing works.

I want he exact same process to happen as a Popup Menu. If you click outside a Popup Menu, but still within the underlying program or forms, the Menu closes. That's what I need the grid to do.
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

 

TinyPortal © 2005-2018