bonjour
j'emploi StringGrid1DrawCell pour formatter mes colonnes en fonction des données
mais comment éviter de faire " begin end else begin end ect" voir exemple ci dessous
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  With Sender As TStringGrid Do With Canvas Do
  Begin 
      If gdFixed in State
      Then Brush.Color := clSkyBlue
      Else If gdSelected In State
      Then Brush.Color := clNavy
      Else Brush.Color := clWhite;
      FillRect(Rect);
 
      If gdSelected In State Then
           SetTextColor(Canvas.Handle,clWhite)
      Else SetTextColor(Canvas.Handle,clBlue);
 
     if (Acol=0) and (arow=1) then begin
        font.Size:=16;
       SetTextColor(Canvas.Handle,clblue);
       end
       else
       if (Acol=1) and (arow>0) then begin
        font.Size:=14;
       SetTextColor(Canvas.Handle,clred);
        end
        else
     if (Acol=2) and (arow>0) then begin
           font.Size:=12;
       SetTextColor(Canvas.Handle,clgreen);
      end
      else
         font.Size:=8;
 
    DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]), -1, Rect ,
      DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE  );
end;