我是业余爱好者
各位兄弟,帮忙,我只想改变字段为预百的颜色怎么做
下面的代码会改变整行的颜色,弄了3个多小时了都没有搞好with TMyCustomerDBGrid(Sender) do
begin if aa.FieldByName('预百').AsString='对' then
canvas.Brush.Color:=clred
else
if aa.FieldByName('预百').AsString='错' then
Canvas.Brush.Color:=clgreen;
Canvas.Font.Color:=clBlack;
// canvas.fillrect(rect);
canvas.textout(rect.left+4,rect.top+4,column.Field.AsString);
END;如果把这些代码放在事件DBGrid1DrawDataCell里则要在单击时触发而我所想要的是当程序运行时,根据预百这个字段的值显示不同的颜色,所有的记录都要.怎么做
各位兄弟,帮忙,我只想改变字段为预百的颜色怎么做
下面的代码会改变整行的颜色,弄了3个多小时了都没有搞好with TMyCustomerDBGrid(Sender) do
begin if aa.FieldByName('预百').AsString='对' then
canvas.Brush.Color:=clred
else
if aa.FieldByName('预百').AsString='错' then
Canvas.Brush.Color:=clgreen;
Canvas.Font.Color:=clBlack;
// canvas.fillrect(rect);
canvas.textout(rect.left+4,rect.top+4,column.Field.AsString);
END;如果把这些代码放在事件DBGrid1DrawDataCell里则要在单击时触发而我所想要的是当程序运行时,根据预百这个字段的值显示不同的颜色,所有的记录都要.怎么做
并加入 DbGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,[])
就可以了
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var index:integer;
Mysg:TDBGrid;
begin
Mysg := TDBGrid(Sender);
if (Column.Index=0) then begin
if ((AdvanceADO.RecNo<=AdvanceADO.RecordCount)and(AdvanceADO.RecNo>0)) then begin
Mysg.Canvas.FillRect(Rect);
Mysg.Canvas.TextOut(Rect.Left+2,Rect.Top+2,IntToStr(Mysg.DataSource.DataSet.RecNo));
end;
end else if (Column.Index=1) then begin
if ((AdvanceADO.RecNo<=AdvanceADO.RecordCount)and(AdvanceADO.RecNo>0)) then begin
index := Column.Field.AsInteger-1;
Mysg.Canvas.FillRect(Rect);
ImageList2.Draw(Mysg.Canvas,((Rect.Left+Rect.Right-ImageList1.Width)div 2),Rect.Top,index);
end;
end;
end;
http://www.tomore.com/ 上面有下!