Solved

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

Posted on 2011-03-19
12
1,337 Views
Last Modified: 2013-11-23
How to use " TdrawGrid " for data.
Like strings . In Delphi
0
Comment
Question by:dabbiX
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 32

Expert Comment

by:ewangoya
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:ewangoya
ID: 35171573
Sorry for the typos. Its
Rect: TRect
0
 
LVL 32

Accepted Solution

by:
ewangoya 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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:ewangoya
ewangoya 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 100

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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