Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-19
12
Medium Priority
?
1,587 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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

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…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

721 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