Solved

How to use " TdrawGrid " for data.......in Delphi

Posted on 2011-03-19
12
1,526 Views
Last Modified: 2013-11-23
How to use " TdrawGrid " for data.
Like strings . In Delphi
0
Comment
Question by:dabbiX
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35171561
Use draw cells event
Tform1.drawgrid1drawcell(sender: tobjet; acol, arow: integer; rest:trect; state: tdrawstate);
begin
  DrawGrid1.Canvas.TextOut(Rect.Left, Rest.Top, 'you strings);
end;
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35171573
Sorry for the typos. Its
Rect: TRect
0
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 250 total points
ID: 35171605
Much cleaner

Procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow : Integer: Rect: TRect; State: TDrawState);
Begin
  DrawGrid1.Canvas.TextOut(Rect.Left, Rect.Top, 'your string ');
End;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dabbiX
ID: 35171677
ok Tanks

I got 5 tims in the left side.
but how can I put it  in cell .
like row 3 and colum 4. ' my text'
0
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 250 total points
ID: 35171701
Test the ARow and ACol:
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if (ARow = 3) and (ACol = 4) then
    begin
      DrawGrid1.Canvas.FillRect(Rect);
      DrawGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, ' my text');
    end;
end;

Open in new window

0
 

Author Comment

by:dabbiX
ID: 35171941
ok
  DrawGrid1.Col := 3;
  DrawGrid1.Row := 0;
  lx := DrawGrid1.row ;
  dy := DrawGrid1.Col ;
  DrawGrid1.Canvas.TextOut(lx,dy,'colum name');
This set name in colum 0......

How can I put name in colum 1 to 4.........
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35171998
Is this what you mean:
var
  col,row:integer;
begin
  for col := 0 to DrawGrid1.ColCount-1 do
    for row:= 0 to DrawGrid1.RowCount-1 do
      DrawGrid1.Canvas.TextOut(DrawGrid1.CellRect(col,row).Left+3,DrawGrid1.CellRect(col,row).Top+3,'colum name');
//...

Open in new window

0
 

Author Comment

by:dabbiX
ID: 35172742
ok
ups
I got 'Colum name' over all.

How can I have separate name in Colum heat.

like... Colum1 = name
         Colum 2 = Home
         Colum 3 = Country
0
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 250 total points
ID: 35172818
Then it becomes as follows:
DrawGrid1.Canvas.TextOut(DrawGrid1.CellRect(0,0).Left+3,DrawGrid1.CellRect(0,0).Top+3, 'Name');
DrawGrid1.Canvas.TextOut(DrawGrid1.CellRect(1,0).Left+3,DrawGrid1.CellRect(1,0).Top+3, 'Home');
DrawGrid1.Canvas.TextOut(DrawGrid1.CellRect(2,0).Left+3,DrawGrid1.CellRect(2,0).Top+3, 'Country');

Open in new window

0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 250 total points
ID: 35172854

You need to be reading the data from somewhere, Declare an array to hold the column data eg
const
  CHeader: array[0..2] of string = ('Name', 'Home', 'Country');


However for what you are trying to do, you are better off using a TClientDataset and TDBGrid and you dont have to worry about drawing data manually
const 
  CHeader: array[0..2] of string = ('Name', 'Home', 'Country');

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if ARow = 0 then
  begin
    DrawGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, CHeader[ACol]);
  end;
end;

Open in new window

0
 
LVL 101

Expert Comment

by:mlmcc
ID: 35452392
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

615 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