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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1659
  • Last Modified:

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

How to use " TdrawGrid " for data.
Like strings . In Delphi
0
dabbiX
Asked:
dabbiX
  • 4
  • 3
  • 3
  • +1
4 Solutions
 
Ephraim WangoyaCommented:
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
 
Ephraim WangoyaCommented:
Sorry for the typos. Its
Rect: TRect
0
 
Ephraim WangoyaCommented:
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
Independent Software Vendors: 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!

 
dabbiXAuthor Commented:
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
 
jimyXCommented:
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
 
dabbiXAuthor Commented:
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
 
jimyXCommented:
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
 
dabbiXAuthor Commented:
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
 
jimyXCommented:
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
 
Ephraim WangoyaCommented:

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now