[0.9.31] StringGrid : TBitMap en Cells[0, aRow] avec FixedCols :=1
Bonjour,
Dans une StringGrid en goRowSelect :=True, comment assigne-t-on un TBitMap (dans l'évènement OnDrawcell) à une cellule d'une FixedCols à partir d'une condition (gdSelected = True) or (gsFocused = True) ?
Ceci fonctionne
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| procedure TForm1.FormCreate(Sender: TObject);
begin
With StringGrid1 do begin
FixedCols := 0; //<---------------
if not (goRowSelect in Options) then Options:= Options + [goRowSelect];
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
var
BitMap : TBitMap;
begin
if (gdSelected in aState) or (gdFocused in aState) then
if assigned(Image1.Picture.Bitmap) then begin
Bitmap := TBitmap.Create;
Bitmap.Assign(Image1.Picture.Bitmap);
{ Dessin du fond }
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(0, aRow), Bitmap);
Bitmap.Free;
end;
end; |
Mais, si je remplace FixedCols := 0 par FixedCols :=1, le TBitmap n'est plus assigné ce qui me laisse penser que le (gdSelected =True) or (gsFocused = True) n'est plus "détecté" car le code suivant l'assigne correctement à toutes les Cells[0, aRow] :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| procedure TForm1.FormCreate(Sender: TObject);
begin
With StringGrid1 do begin
FixedCols := 1;
if not (goRowSelect in Options) then Options:= Options + [goRowSelect];
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
var
BitMap : TBitMap;
begin
//if (gdSelected in aState) or (gdFocused in aState) then
if assigned(Image1.Picture.Bitmap) then begin
Bitmap :=TBitmap.Create;
Bitmap.Assign(Image1.Picture.Bitmap);
{ Dessin du fond }
StringGrid1.Canvas.StretchDraw(StringGrid1.CellRect(0,aRow), Bitmap);
Bitmap.Free;
end;
end; |
Donc, je suppose que je m'y prends mal. Quelle est la solution ?
Merci. Cordialement