delphi 如何改变符合条件的dbgrid背景色?
我想做一个查询,比如,我想把姓张的员工的姓名都显示出来,dbgrid的显示背景色变为红色,其他的颜色不变。请问如何实现?...
我想做一个查询,比如,我想把姓张的员工的姓名都显示出来,dbgrid的显示背景色变为红色,其他的颜色不变。请问如何实现?
展开
1个回答
展开全部
可以在DBGrid的DrawColumnCell事件里面控制
uses
StrUtils;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if AnsiStartsText('张', ADOTable1.FieldByName('name').AsString) then
(Sender as TDBGrid).Canvas.Brush.Color := clRed;
//(Sender as TDBGrid).Canvas.Font.Color := clRed;//如果改字体颜色用这个
(Sender as TDBGrid).DefaultDrawDataCell(Rect, Column.Field, State);
end;
uses
StrUtils;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if AnsiStartsText('张', ADOTable1.FieldByName('name').AsString) then
(Sender as TDBGrid).Canvas.Brush.Color := clRed;
//(Sender as TDBGrid).Canvas.Font.Color := clRed;//如果改字体颜色用这个
(Sender as TDBGrid).DefaultDrawDataCell(Rect, Column.Field, State);
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询