Solved

DBGRID title

Posted on 2004-09-01
3
355 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now