Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-07

StringGrid

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Kamen Ketev

Hello, I want to change certain cells in StringGrid. Here is an example, but it changes all cells. Any idea where is wrong?

procedure TForm1.StringGrid1Click(Sender: TObject);
var
 i, j: integer;
begin
 for i := 1 to 4 do
 for j := 1 to 4 do Begin

if i=j

 then StringGrid1.Font.Style := [fsBold]
 else StringGrid1.Font.Style := [];
 StringGrid1.Cells[i,j] := 'StrTest';
 end;
end;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130707/bb0db621/attachment.html>

Reply by email

zeljko
to Kamen Ketev
Kamen Ketev wrote 15 lines
Hello, I want to change certain cells in StringGrid. Here is an example, but it changes all cells. Any idea where is wrong? procedure TForm1.StringGrid1Click(Sender: TObject); var i, j: integer; begin for i := 1 to 4 do for j := 1 to 4 do Begin if i=j then StringGrid1.Font.Style := [fsBold] else StringGrid1.Font.Style := []; StringGrid1.Cells[i,j] := 'StrTest'; end; end;

That's wrong. You're changing TStringGrid.Font. If you want to change font of one (few) cells only then you should use OnDrawCell or something similar where you can change canvas.Font per cell.

z.

Reply by email

Vojtěch Čihák
to Kamen Ketev: Hello, I want to change certain cells in StringGrid. Here is an example, but it changes…
Try this:
?
procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
 aState: TGridDrawState);
begin
? if aCol = aRow then (Sender as TStringGrid).Canvas.Font.Style := [fsBold];
end;
?
Vojt?ch?
______________________________________________________________
Show quoted text 5 lines
Od: "Kamen Ketev" Komu: Datum: 07.07.2013 02:29 P?edm?t: [Lazarus] StringGrid

Hello, I want to change certain cells in StringGrid.?

----------

Reply by email

Kamen Kamen

That did it, thank you both!

-------- ?????????? ????? --------
??: Vojt?ch ?ih?k
???????: Re: [Lazarus] StringGrid
??: Lazarus mailing list
????????? ??: ??????, 2013, ??? 7 13:32:50 EEST

Try this:

 procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
 aState: TGridDrawState);
begin
 if aCol = aRow then (Sender as TStringGrid).Canvas.Font.Style := [fsBold];
end;

Vojt?ch

______________________________________________________________

Show quoted text 9 lines
Od: "Kamen Ketev" Komu: Datum: 07.07.2013 02:29 P?edm?t: [Lazarus] StringGrid

Hello, I want to change certain cells in StringGrid.

----------

Reply by email