Recent

Author Topic: DBGrid and Text Wrapping  (Read 8907 times)

gkelby

  • New Member
  • *
  • Posts: 24
DBGrid and Text Wrapping
« on: March 03, 2014, 12:55:17 am »
Does anyone know how to wrap the text in the header column of a DBGrid component?  I have several columns that require a small width where the text in the header column is too long for the column width.  I would like to be able to wrap the header text within the defined column width.  I can't seem to find any options to do this in the Object Inspector.

Thanks...
GK

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
Re: DBGrid and Text Wrapping
« Reply #1 on: March 03, 2014, 11:37:50 am »
Did you try something like this:
Quote
DBGrid1.Columns.Items.Title.Caption:=newname;
DBGrid1.Columns.Items.Width:=widthn;
I try to google "lazarus dbgrid column name" and got "About 342,000 results (0.39 seconds)"

Best Regards
Jean-Christophe

GADZombie

  • New Member
  • *
  • Posts: 46
  • 8bitrlz
    • Zombie Mastah
Re: DBGrid and Text Wrapping
« Reply #2 on: March 03, 2014, 11:46:30 am »
Does anyone know how to wrap the text in the header column of a DBGrid component?  I have several columns that require a small width where the text in the header column is too long for the column width.  I would like to be able to wrap the header text within the defined column width.  I can't seem to find any options to do this in the Object Inspector.

If there is no other method, just user OwnerDraw and draw your text using DrawText method with DrawFormat := DT_TOP or DT_WORDBREAK;
You'll have word breaking and other goodies with this method (i.e. you could add an icon to text or change anything else.

krzynio

  • Full Member
  • ***
  • Posts: 110
    • Krzynio's home page
Re: DBGrid and Text Wrapping
« Reply #3 on: March 11, 2014, 09:27:46 pm »
Hi!
Try hacking DBGrid.
Below article should be helpful. I wrote my own DBGrid as descendant of TDBGrid with filters in header row using this method. Using it allows you to change height of header row, than you can use OwnerDraw for writing on it.

http://delphi.about.com/od/oopindelphi/l/aa082603a.htm

You may also be interested in KGrid instead of standard DBGrid.

http://www.tkweb.eu/en/delphicomp/kgrid.html
« Last Edit: March 11, 2014, 09:29:58 pm by krzynio »
Debian 12.8 x64, / Windows 11 PL - latest updates
Lazarus 3.6

gkelby

  • New Member
  • *
  • Posts: 24
Re: DBGrid and Text Wrapping
« Reply #4 on: March 23, 2014, 08:51:14 am »
Thanks for the responses.  I've realized there is no easy answer so instead I've named the grid columns to the table field names and gave the columns their own captions.  That works with the "Select *..." format.  I'll just have to wait for, maybe, an enhancement upgrade but I won't be holding my breath...

Thanks...
GK
 

patyi

  • Full Member
  • ***
  • Posts: 168
Re: DBGrid and Text Wrapping
« Reply #5 on: March 23, 2014, 05:02:29 pm »
Hi !

Why don't try RxDBGrid ? RxDBGrid has ability of multi line header with | character delimiter !

gkelby

  • New Member
  • *
  • Posts: 24
Re: DBGrid and Text Wrapping
« Reply #6 on: March 24, 2014, 01:01:09 am »
Hi;

Sorry, where would I find RxDBGrid?  I do see it as part of the controls set in Lazarus 1.1.99.

Thanks...
Gk.

patyi

  • Full Member
  • ***
  • Posts: 168
Re: DBGrid and Text Wrapping
« Reply #7 on: March 24, 2014, 07:30:55 am »

 

TinyPortal © 2005-2018