改变dbgrid字体的颜色(200分)

U

ugvanxk

Unregistered / Unconfirmed
GUEST, unregistred user!
我有些数据显示再dbgrid 中
格式为
100。。。
100。。。
。。。
200。。。
200。。。
。。。
300。。。
300。。。
。。。
我想移动到100时改变100的所有记录的颜色
移动到200,其他的地方颜色还原,200改变颜色
 
procedure TQryResult_F.DBGrid2DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if qrypara.fieldbyname('dot_time').asinteger=ndot_time then
begin
dbgrid2.Canvas.Font.Color:=clblue;
dbgrid2.DefaultDrawColumnCell(rect,datacol,column,state);
end else
begin
dbgrid2.Canvas.Font.Color:=clblack;
dbgrid2.DefaultDrawColumnCell(rect,datacol,column,state);
end;


end;

procedure TQryResult_F.QryparaAfterScroll(DataSet: TDataSet);
begin
ndot_time:=qrypara.fieldbyname('dot_time').asinteger;
dbgrid2.Invalidate;
end;

我已解决,不知这种方法好不好
 
可能,发分
 
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with Sender as TDBGrid, DataSource.DataSet do
if (FieldByName('AmountPaid').AsFloat > 15000) then
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [fsBold],
clYellow, clRed);
end;

{This is the workhorse routine that does the drawing.}
procedure TForm1.DrawField(const Value : String;
const Rect : TRect;
vCanvas : TCanvas;
vFont: TFont;
vAlignment: TAlignment;
FontStyle : TFontStyles;
FontColor : TColor;
BGColor : TColor);
var
I : Integer;
begin
I := 0;

//First, fill in the background color of the cell
vCanvas.Brush.Color := BGColor;
vCanvas.FillRect(Rect);
//SetBkMode ensures that the background is transparent
SetBkMode(Canvas.Handle, TRANSPARENT);

//Set the passed font properties
vCanvas.Font := vFont;
vCanvas.Font.Color := FontColor;
vCanvas.Font.Style := vCanvas.Font.Style + FontStyle;

//Set Text Alignment
case vAlignment of
taRightJustify :
begin
SetTextAlign(vCanvas.Handle, TA_RIGHT);
I := Rect.Right - 2;
end;

taLeftJustify :
begin
SetTextAlign(vCanvas.Handle, TA_LEFT);
I := Rect.Left + 2;
end;

taCenter :
begin
SetTextAlign(vCanvas.Handle, TA_CENTER);
I := (Rect.Right + Rect.Left) DIV 2;
end;
end; { case }

//Draw the text
vCanvas.TextRect(Rect, I, Rect.Top + 2, Value);
SetTextAlign(vCanvas.Handle, TA_LEFT);
end;
 
另外,我还有个问题
我有个表,有很多字段200个字节的长度,但我用dbgrid 显示,显示不完全
有没有好的组件,可以在显示部分加按钮,点击显示
dbgrid 本身好像只支持一个
字段不是memo 属性,是文本 属性
 
这方面的组件很多啊,到深度历险、凌云天地找找吧。
 
多人接受答案了。
 
顶部