改变Dbgrid的选定色。 procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState); begin if gdSelected in state then SetBkColor(dbgrid1.canvas.handle,clgreen) else setbkcolor(dbgrid1.canvas.handle,clwhite); dbgrid1.Canvas.TextRect(rect,0,0,field.AsString); dbgrid1.Canvas.Textout(rect.Left,rect.Top,field.AsString); end;
意思就是说比如逻辑型,为true时显示红色。为false时显示黑色。
2、程序设置; procedure Tinfo.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if query1.FieldByName(’all’).asstring>40’ then begin dbgrid1.Canvas.Font.Color:=clred; dbgrid1.Canvas.Brush.color:=clyellow; end else begin dbgrid1.Canvas.Font.Color:=clblue; dbgrid1.Canvas.Brush.color:=clyellow; end;
你说的意思不过明白 如果是直接控制某一列是什么特殊内容可以 procedure TForm1.FormCreate(Sender: TObject); begin IF DBGrid1.Columns[0].Title.Caption='1' then DBGrid1.Columns[0].Color:=Clred; end;或者 procedure TForm1.FormCreate(Sender: TObject); begin IF DBGrid1.Columns[0].FieldName={你要的条件列名} then DBGrid1.Columns[0].Color:=Clred; end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if Table1.FieldByName('字段').AsInteger = 10000 then {我这里是判断这个字段的内容大于10000,然后显示为蓝色} Table1.Canvas.Font.Color := clBlue; Table1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end;
procedure Tinfo.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if query1.FieldByName(’all’).asstring>40’ then
begin
dbgrid1.Canvas.Font.Color:=clred;
dbgrid1.Canvas.Brush.color:=clyellow;
end
else
begin
dbgrid1.Canvas.Font.Color:=clblue;
dbgrid1.Canvas.Brush.color:=clyellow;
end;
dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
end;
检索没一格的值 值里有特殊内容就改边其颜色!~
你只要会改边dbgrid某一格的颜色就而可以了啊, 这不难的~
如果是直接控制某一列是什么特殊内容可以
procedure TForm1.FormCreate(Sender: TObject);
begin
IF DBGrid1.Columns[0].Title.Caption='1' then
DBGrid1.Columns[0].Color:=Clred;
end;或者
procedure TForm1.FormCreate(Sender: TObject);
begin
IF DBGrid1.Columns[0].FieldName={你要的条件列名} then
DBGrid1.Columns[0].Color:=Clred;
end;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Table1.FieldByName('字段').AsInteger = 10000 then
{我这里是判断这个字段的内容大于10000,然后显示为蓝色}
Table1.Canvas.Font.Color := clBlue;
Table1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;