Bonsoir à tous,

J'utilise la police wingdings 2 pour afficher une case à cocher dans une stringgrid, cependant, je rencontre un problème d'affichage.
Exemple:
Quand je clique sur la ligne 3 par exemple pour afficher la case cocher et ensuite sur la ligne 4, il n'y a pas de problème. Ensuite, je clique de nouveau sur la ligne 3 et il m'affiche la case non coché, mais il le fait aussi sur la ligne 4.
Voici le code sous Delphi 2009
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Grids;
 
type
  TForm1 = class(TForm)
    Panel1: TPanel;
    StringGrid1: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure StringGrid1Click(Sender: TObject);
  private
    { Déclarations privées }
    iACol: integer;
    iARow: integer;
  public
    { Déclarations publiques }
    Value: String;
  end;
 
const
  sCheckOff = '0';
  sCheckOn  = 'R';
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
var
  i: integer;
begin
  for i := StringGrid1.FixedRows to StringGrid1.RowCount -1 do
  begin
    Value:= sCheckOff;
  end;
end;
 
procedure TForm1.StringGrid1Click(Sender: TObject);
begin
  iACol:= TStringGrid(StringGrid1).Col;
  iARow:= TStringGrid(StringGrid1).Row;
 
  Value:= sCheckOff;
  if StringGrid1.Cells[iACol, iARow] = sCheckOff then
    Value:= sCheckOn;
end;
 
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if ACol = 1 then
  begin
    with TStringGrid(Sender), Canvas do
    begin
      Font.Name:= 'Wingdings 2';
      Font.Size:= 15;
 
      Cells[iACol, iARow]:= Value;
 
      TextOut(Rect.Left +25, Rect.Top +1, Value);
    end;
  end;
end;
 
end.
Quelqu'un pourrait-il éclairer ma lanterne ?
Jeankiki