我想在OnCellClick
事件中OnCellClick
DBGrid
中被单击的行的颜色,并在下一个OnCellClick
事件之前将网格的状态保存到下一个–而不是另一行将被着色,等等。有人知道我如何实现这一目标吗?
Well, it will be rly bad decision to code rendering inside OnCellClick
. Basically in OnCellClick
you just simply need to save selected RecNo
. Like this:
procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
tag:=DBGrid1.SelectedField.DataSet.RecNo;
end;
And then u need to modify OnDrawDataCell
func like this:
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);
begin
if(Field.DataSet.RecNo=tag)then begin
DBGrid1.Canvas.Brush.Color:=clYellow;
DBGrid1.Canvas.Font.Color:=clNavy;
end else begin
DBGrid1.Canvas.Brush.Color:=clWhite;
DBGrid1.Canvas.Font.Color:=clRed;
end;
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.DefaultDrawDataCell(Rect, Field, State);
end;
PS if u have multiple entries with same RecNo, u should choose another property, which will be unical for each row.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.