Solved

DBGRID title

Posted on 2004-09-01
3
357 Views
Last Modified: 2012-05-05
hi
i have a question about DBGRID
i have some columns in my dbgrid
i wanna show my columns's  title in 2 line, like this
   --------------------------------------------
   |   project    |  project  |
   |   number   |  name    |
   --------------------------------------------

i wrote this codes but it didnt work
DBGrid2.Columns.Items[0].Title.Caption:='project' + #10 +'number';
what can i do for it

if i want to have my title in 2 seperated line what i must do
   --------------------------------------------
   |           project           |
   --------------------------------------------
   |   number   |  name    |
   --------------------------------------------


plz help me
tanxfull
mahsa
0
Comment
Question by:Mahsa60
3 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11950109
0
 
LVL 6

Accepted Solution

by:
Amir Azhdari earned 70 total points
ID: 11960530
MAhsa60,
you can try with stringgrids instead of dbgrids ,
take a look at this code :


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    StringGrid1: TStringGrid;
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);

var line1,line2:string;
    ptr:integer;
    padding:integer;
begin
ptr:=pos(';',stringgrid1.Cells[acol,arow]);
if ptr>0 then begin
 line1:=copy(stringgrid1.Cells[acol,arow],1,ptr-1);
 line2:=copy(stringgrid1.Cells[acol,arow],ptr+1,length(Stringgrid1.Cells[acol,arow])-ptr);
 end
 else
 line1:=stringgrid1.Cells[acol,arow];
 stringgrid1.Canvas.FillRect(rect);
 stringgrid1.Canvas.TextOut(rect.Left+4,rect.Top+2,line1);
  if ptr>0 then
 stringgrid1.Canvas.TextOut(rect.Left+4,rect.Top-stringgrid1.Canvas.Font.Height+3,line2);


end;




procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
stringgrid1.RowHeights[0]:=stringgrid1.DefaultRowHeight*2-10;

stringgrid1.Cols[1].Text:='Project;Number';
stringgrid1.Cols[2].Text:='Project;Name';

// you can try to execute the query and then write that to the grid
for i:=1 to 3 do
stringgrid1.Cells[i,1]:='TEST';

end;

end.









// DFM FILE

object Form1: TForm1
  Left = 192
  Top = 107
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 288
    Top = 408
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object StringGrid1: TStringGrid
    Left = 64
    Top = 40
    Width = 585
    Height = 233
    Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing]
    TabOrder = 1
    OnDrawCell = StringGrid1DrawCell
  end
end
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12001193
What you will have to do is to inherit from TCustomDBGrid and override the DrawCell procedure and then
modify the DrawTitleCell  procedure to do the multi-line stuff.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 104
Send message from delphi to whatsapp, is it possible? 3 1,443
drawing animated level bar based on numbers 3 97
enhance the following code 3 31
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question