Lazarus

Programming => Databases => Topic started by: xinyiman on January 08, 2019, 11:26:04 am

Title: Title with filter box
Post by: xinyiman on January 08, 2019, 11:26:04 am
Hi guys, I wanted to ask you something. What if I want to add a TEditBox or any other component to a cell that is the title of a column in a dbgrid?
Title: Re: Title with filter box
Post by: daveinhull on January 09, 2019, 03:03:22 pm
Hi Same question here from me a few weeks ago:
http://forum.lazarus.freepascal.org/index.php/topic,43711.0.html (http://forum.lazarus.freepascal.org/index.php/topic,43711.0.html)

I'ev not had much luck so far so if you get anywhere please share, thanks.

Dave
Title: Re: Title with filter box
Post by: wp on January 09, 2019, 03:36:25 pm
Code: Pascal  [Select][+][-]
  1.   Edit1.BoundsRect := DBGrid1.CellRect(2, 0);  // I am assuming here that the Edit should be in col=2
  2.   Edit1.Show;  
Title: Re: Title with filter box
Post by: daveinhull on January 09, 2019, 04:03:57 pm
Hi, I've done that, but what I've got a problem with is knowing when to show the edit box (or a button).
I was trying to show it using OnDrawColumnCell but this puts it in all rows.

Dave
Title: Re: Title with filter box
Post by: wp on January 09, 2019, 04:16:36 pm
I've got a problem with is knowing when to show the edit box (or a button).
If *you* don't know how should *I* know? What is the edit/button good for? What is the user supposed to do to make it appear?
Title: Re: Title with filter box
Post by: daveinhull on January 09, 2019, 08:01:04 pm
WP, TI'm not wanting the user to decide when to show the button I want it to appear when the DBGrid is drawn. Please see http://forum.lazarus.freepascal.org/index.php/topic,43711.0.html (http://forum.lazarus.freepascal.org/index.php/topic,43711.0.html).

As I said in the post I was trying to use the OnDrawColumnCell to draw the button, did you see that or where you too busy having a go at me?

I wanted top put a button at the top of each column so that the user can press it and get the option to sort and filter on that column. When the OnDrawColumnCell triggers I need to see which row it is drawing and if row 1 (the title row) then I wanted to also draw the button control in the Cell.Rect.
Title: Re: Title with filter box
Post by: lucamar on January 09, 2019, 08:29:47 pm
If you only want it in the Title row then use the OnDrawColumnTitle event, not the OnDrawColumCell.

You should at least skim the docs. Granted that there isn't much on them but the names of proerties, methods and events are quite evocative of what they are meant for. And check the examples. :)
Title: Re: Title with filter box
Post by: daveinhull on January 09, 2019, 08:37:33 pm
Thanks lucamar, I have been trying to find documentation, and the first place I start with is in the Object Inspector, but that event isn't listed!

@wp, anyway, thanks for the pointer to CellRect, which  I'd missed.
Title: Re: Title with filter box
Post by: daveinhull on January 09, 2019, 08:47:33 pm
lucamar, honest I do look at documentation when I can find it  ;)

I've just try doing a search for "OnDrawColumnTitle" both in google using Lazarus PAscal OnDrawColumnTitle and in the on-line help and I can't find anything.

I've got it working now using DrawColumnCell and wp pointer to CellRect, although I'm not sure it is the best way, but it does what I want.

Thanks both.
Title: Re: Title with filter box
Post by: lucamar on January 09, 2019, 09:21:27 pm
If you have the help installed (the CHM files), try searching TDBGrid, then click the "Events" link and there you have it.

The difference with OnDrawColumnCell is that OnDrawColumnTitle is triggered just to draw the title cells, not for all cells in the grid. This not only makes it a more efficient solution but you wont' have to check whether you're in the correct row: you know you are.
Title: Re: Title with filter box
Post by: daveinhull on January 12, 2019, 12:26:20 pm
Hi lucamar,

So I think I've got the right help file (the one that pops up when you press F1 over key word). I can find DBgrids, then TDBGrid and I can see under EventsByName a reference to OnDrawColumnTitle. However it is not in the Object Inspector so I can set a default routine for it that way. And if I tried to set up the event routine n code, the compiler doesn't find it as a member.

Also I'm not sure I'm looking at the right thing because if I follow the reference path down into columns and then into Items I can see in the help a function called CreateTitle, but again this doesn't appear as an option in the code when the editor window pops up after entering the '.'

There are other examples of this, so I'm assuming its me not reading things correctly, for example reference to TColumnTitle, which I can't find how to use.

Any help on my understanding of this would be hugely beneficial in my learning.

Many thanks in advance
Dave

Title: Re: Title with filter box
Post by: wp on January 12, 2019, 01:22:53 pm
I think you are expecting too much of the chm help files; I guess 95% of their content is autogenerated and of little use, and usually they are out-dated...

Please learn how to navigate in the Lazarus source code, this provides the most up-to-date documentation that you can imagine.

Let's assume, you have a TDBGrid on your form and you want to see the events available for it. Ctrl+click on the identifier "TDBGrid" your source code, and Lazarus opens the source file at the position where TDBGrid is implemented. Depending on the version you may be shown the implementation or interface part of the unit - press SHIFT+CTRL+ArrowUp/Down to switch between both sections. When you are in the interface part of TDBGrid in unit grids.pas, you can scroll down a bit and you see a list of all events.

If you have Laz 1.8.4 as suggested by your signature, however, you will not find OnDrawColumnTitle because this event is available in v2.0 or later only. You can try one of the release condidates to get it.

Continued usage of CTRL+Click will bring you anywhere. This is the standard method I am using when studying code.

Another important shortcut is CTRL+b which brings you back to the previously displayed source code position. Note that this is for classical keyboard layout. In the default layout, I think, the key combination is ALT+Left arrow.
Title: Re: Title with filter box
Post by: daveinhull on January 12, 2019, 01:56:08 pm
Many thanks wp, will start down that route :)
Title: Re: Title with filter box
Post by: lucamar on January 12, 2019, 03:22:57 pm
I think you are expecting too much of the chm help files; I guess 95% of their content is autogenerated and of little use, and usually they are out-dated...
[...]
If you have Laz 1.8.4 as suggested by your signature, however, you will not find OnDrawColumnTitle because this event is available in v2.0 or later only.

You're right, of course; I just looked in the source and there's not any OnDrawColumnTitle in version 1.8.4. The mistery then is how it got to the docs ... back to the future?

@daveihull: My apologies for a bad advice; I was mislead by the docs and didn't take the time to check the code.
Title: Re: Title with filter box
Post by: wp on January 12, 2019, 04:15:49 pm
The mistery then is how it got to the docs ... back to the future?
Yes. Maybe the docs is for v2.0?
Title: Re: Title with filter box
Post by: daveinhull on January 12, 2019, 04:22:56 pm
@lucamar, no need to apologize at all, everything helps, from your erroneous point I investigated the docs, put my comment up and wp pushed me to a bettter solution anyway :D
Title: Re: Title with filter box
Post by: lucamar on January 12, 2019, 05:37:26 pm
The mistery then is how it got to the docs ... back to the future?
Yes. Maybe the docs is for v2.0?

Well, they are the standard docs included with the 1.8.4 distribution. It's quite a curious thing: the source doc dbgrids.xml, dated 2015-01-28, does not mention OnDrawColumnTitle. It looks like the package maintainer (or whoever generated the docs) wasn't using the release revision.

At lest I learned my lesson: don't trust the docs and always check the source. :)
TinyPortal © 2005-2018