ورود

View Full Version : سوال: رنگی کردن رکورد جاری در استرینگ گرید



mbshareat
دوشنبه 16 اردیبهشت 1398, 21:56 عصر
سلام.
سوالم فکر کنم ساده است ولی بلد نیستم.میخوام وقتی روی استرینگ گرید کلیک می کنم رکورد جاری رنگی بشه.
فکر می کردم این کد جواب بده ولی کار نکرد:
var
Form1: TForm1;
LastRow:Word=1;
implementation
..
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
I: Integer;
R:TRect;
begin
With StringGrid1 Do
Begin
Canvas.Brush.Color := clWhite;
For I:=1 to ColCount do
Begin
R:=CellRect(I,LastRow);
Canvas.FillRect(R);
Canvas.TextRect(R,R.Left + 2, R.Top + 2, cells[I, LastRow]);
End;
Canvas.Brush.Color := $00FFEBDF;
For I:=1 to ColCount do
Begin
R:=CellRect(I,ARow);
Canvas.FillRect(R);
Canvas.TextRect(R,R.Left + 2, R.Top + 2, cells[I, ARow]);
End;
LastRow:=ARow;
End;
end;

mbshareat
شنبه 21 اردیبهشت 1398, 21:46 عصر
این کد جواب میده اما رنگ ابی تیره رو دوست ندارم.چطور رنگش رو تغییر بدم؟
StringGrid1.Options := StringGrid1.Options + [goRowSelect];

mbshareat
شنبه 21 اردیبهشت 1398, 22:08 عصر
آخرش به این کد رسیدم:گیج:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
const
SelectedColor = $00FFEBDF;
begin
if (state <> [gdFixed]) And (ARow=TStringGrid(Sender).Row) then
with TStringGrid(Sender), Canvas do
begin
Brush.Color := SelectedColor;
FillRect(Rect);
Font.Color:=clBlack;
TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[aCol, aRow]);
end
end;