Solved

DBGRID title

Posted on 2004-09-01
3
354 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
Comment Utility
0
 
LVL 6

Accepted Solution

by:
Amir Azhdari earned 70 total points
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

11 Experts available now in Live!

Get 1:1 Help Now