Solved

DBGRID title

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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