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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
procedure TFlistfact.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with stringgrid1 do
begin
if gdselected in state then
begin
stringgrid1.Canvas.Brush.Color:=clactivecaption;
end
else
if gdfixed in state then
stringgrid1.Canvas.Brush.Color:=clbtnface
else
begin
if (arow div 2)=(arow/2) then
stringgrid1.Canvas.Brush.Color:=clwindow
else
stringgrid1.Canvas.Brush.Color:=clyellow;
end;
stringgrid1.Canvas.TextRect(rect,rect.Left,rect.Top,stringgrid1.Cells[acol,arow]);
if gdfocused in state then
stringgrid1.Canvas.DrawFocusRect(rect);
end;
With Sender As TStringGrid Do With Canvas Do
Begin
//Dessin du fond
FillRect(Rect);
//Sélection de la couleur de texte
If gdSelected In State Then
SetTextColor(Canvas.Handle,clwhite)
Else SetTextColor(Canvas.Handle,clblack);
//Dessin du texte en utilisant la fonction API
If Arow>0 Then
Begin
if ACol in [3..8] then
DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]), -1, Rect ,
DT_RIGHT or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE )
else
DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]), -1, Rect ,
DT_center or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE );
End
Else
DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]),-1, Rect ,
DT_center or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE );
End;
if RowsSelected.IndexOf(ARow)>-1 then
begin
StringGrid1.Canvas.Brush.Color:=clRed;
stringgrid1.canvas.fillrect(rect);
stringgrid1.canvas.TextOut(Rect.Left,Rect.Top,stringgrid1.Cells[ACol,ARow]);
end;
end;
procedure TFlistfact.Button3Click(Sender: TObject); //Cest mon bouton pour sélectionner ou désélectionner ligne par ligne
Var
index:integer;
Begin
if (stringgrid1.Selection.Left>=stringgrid1.FixedCols) and (stringgrid1.Selection.Right>(stringgrid1.ColCount-1)) then
begin
if stringgrid1.Row > 0 then
begin
if LastRowClicked=-1 then Exit;
index:=RowsSelected.IndexOf(LastRowClicked);
if index>-1
then RowsSelected.Delete(index)
else RowsSelected.Add(LastRowClicked);
StringGrid1.Invalidate;
stringgrid1.col:=1;
try
stringgrid1.Row:=stringgrid1.Row+1;
except
stringgrid1.row:=stringgrid1.row-1;
end;
end;
end;
end;
procedure TFlistfact.Button5Click(Sender: TObject);
var
i:integer;
begin
if button5.Caption='&Tout Sélectionner' then
begin
for i:=1 to stringgrid1.RowCount-1 do
begin
rowsselected.Add(i);
stringgrid1.Invalidate;
button5.Caption:='&Tout Désélectionner';
end;
end
else
begin
for i:=stringgrid1.RowCount-2 downto 0 do //Alors ici je ne comprends pas pourquoi cela marche que comme cela ??????
begin
rowsselected.Delete(i);
stringgrid1.Invalidate;
button5.Caption:='&Tout Sélectionner';
end;
end;
end; |