小编Mam*_*yev的帖子

如何为DBGrid特殊细胞着色?

我有一个只有"是"和"否"值的列.我想如果列值为"是",则只有该单元格背景颜色为红色,否则为"否",则背景颜色为黄色,但此代码为整行着色:

if ADOTable1.FieldByName('Clubs').AsString = 'yes' then
begin
  DBGrid1.Canvas.Brush.Color := clRed;
  DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
Run Code Online (Sandbox Code Playgroud)

编辑

谢谢你的回复.我的真实代码看起来像那样."netice"列只有"L,D,W".

if Column.FieldName = 'netice' then
 begin
 if ADOTable1.FieldByName('netice').AsString = 'L' then
 DBGrid1.Canvas.Brush.Color := clgreen ;
 if ADOTable1.FieldByName('netice').AsString = 'D' then
 DBGrid1.Canvas.Brush.Color := clRed ;
 if ADOTable1.FieldByName('netice').AsString = 'W' then
 DBGrid1.Canvas.Brush.Color := clYellow ;
 end;
 DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
 end;
Run Code Online (Sandbox Code Playgroud)

但我需要L - 绿色,D - 红色,W - 黄色我正在使用Delphi 2010.

在此输入图像描述

delphi dbgrid delphi-2010

4
推荐指数
1
解决办法
1万
查看次数

无法关闭或打开并激活或停用ADOQuery1

两个代码都正常工作.但是不能ADOQuery1.close或ADOQuery1.open以及活动或非活动的ADOQuery1来查看更改.要查看更新的更改,我必须重新执行项目.提前致谢

procedure TForm1.Button4Click(Sender: TObject);
begin    
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('update new set net='''+Edit1.Text+''' ' );
ADOQuery1.SQL.Add('where code=16');
ADOQuery1.ExecSQL;


procedure TForm1.Button4Click(Sender: TObject);
begin 
ADOQuery1.Active:=false;
ADOQuery1.SQL.Text := 'update new set net=:num where code=16';
ADOQuery1.Parameters.ParamByName('num').Value := Edit1.Text;
ADOQuery1.ExecSQL;
Run Code Online (Sandbox Code Playgroud)

delphi ms-access

0
推荐指数
1
解决办法
202
查看次数

标签 统计

delphi ×2

dbgrid ×1

delphi-2010 ×1

ms-access ×1