请问这样得到DBGRID当前行的颜色

解决方案 »

  1.   

    在onDRawColoredDBGrid事件里加下面的代码procedure TForm1.ColoredDBGrid1 DRawColoredDBGrid 
    (Sender: TObject;  Field: TField; var Color: 
    TColor; var Font: TFont);
    Var
      p : Integer;
    begin
        p := Table1.FindField('yourField').AsInteger;//取当前记录
        if ... (判断是否要突出颜色显示)
          Color := clGreen;
          Font.Style := [fsItalic];   
    end;这是判断当前行的值是否满足 if 条件的要求,如果满足,就突出颜色
    你可以根据需要自己修改如果只是突出是当前行
    procedure Tfmone.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
    if (Rect.Top = TStringGrid(DBGrid1).CellRect(TStringGrid(DBGrid1).col,TStringGrid(DBGrid1).row).top)
     and(not (gdFocused in State)) then
     Dbgrid1.Canvas.Brush.Color := clmoneygreen;
     DBGrid1.DefaultDrawDataCell(Rect, Column.Field, State);
    end;