Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DBGRID title

Posted on 2004-09-01
3
Medium Priority
?
363 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 280 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview

782 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