Solved

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

Posted on 2011-03-19
12
1,421 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Communication Between RC4 Delphi <-> PHP 3 123
FMX StringGrid1->Canvas->FillRect Problem 3 176
Magic Software info 18 139
Sending files from  idTcpServer Socket to idTcpClient 2 44
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

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