StringGrid中第一列是判断这一行属性的。默认值为“是”,用户单击这格时变为“否”,再单击时变为“是”。现在要求变为“否”,这一整行背景为红色,请问怎么实现?
以下是我写的,但只能改变一格,而不是一行。
procedure TChangeofDataForm.fromStringGridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
if ARow >0 then
begin
if fromStringGrid.Cells[Acol,ARow] = '否' then
begin
for ACol := 1 to fromStringGrid.ColCount do
begin
fromStringGrid.Canvas.Font.Color := clBlack;
fromStringGrid.Canvas.Brush.Color := clred;
fromStringGrid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2,fromStringGrid.Cells[ACol, ARow]);
end;
end;
end;
end;
以下是我写的,但只能改变一格,而不是一行。
procedure TChangeofDataForm.fromStringGridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
if ARow >0 then
begin
if fromStringGrid.Cells[Acol,ARow] = '否' then
begin
for ACol := 1 to fromStringGrid.ColCount do
begin
fromStringGrid.Canvas.Font.Color := clBlack;
fromStringGrid.Canvas.Brush.Color := clred;
fromStringGrid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2,fromStringGrid.Cells[ACol, ARow]);
end;
end;
end;
end;
解决方案 »
- 调试时出现:stream might not have been initialized
- IdTcpServer使用Timer限制客户端连接的时间出问题。
- 初学者的简单问题,耽误路过的人一小会儿
- 紧急求救,读曲线的值
- 下载的例子,老是出错,老说内存或是ntdll.dll的问题
- 我的程序中用到了indy控件,是在主界面中用TIdAntiFreeze还是在线程中用?
- 怎样把edit.text中的十六进制的字符串转化为十进制数显示在另外的edit中
- 关于MDI窗口的小问题
- 怎样做一个监视桌面上是不是有一个标题为"Apple"的窗口,一旦有,马上关闭
- 这个问题有点急
- 急问:如何获得及设置本机的ip地址,子网掩码,网关,dns服务器等。
- 关于如何在Dbgrid中显示备注型字段的问题?
改:
for x := 1 to fromStringGrid.ColCount do
begin
fromStringGrid.Canvas.Font.Color := clBlack;
fromStringGrid.Canvas.Brush.Color := clred;
fromStringGrid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2,fromStringGrid.Cells[x, ARow]);
begin
if (ARow >0 ) and (ACol > 0) then
begin
if fromStringGrid.Cells[1,ARow] = '否' then // 第一列为否就着色
begin
fromStringGrid.Canvas.Font.Color := clBlack;
fromStringGrid.Canvas.Brush.Color := clred;
fromStringGrid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2,fromStringGrid.Cells[ACol, ARow]);
end;
end;
end;
TStringGrid.Repaint
是dbgrid的颜色操作,你参考下