请教如何将dbgrid当前选择的行变成其它颜色? 多谢了!!!!!!!!

解决方案 »

  1.   

    DbGrid的DrawColumnCell事件if ((State = [gdSelected]) or (State=[gdSelected gdFocused])) then
    DbGrid1.Canvas.Brush.color:=clRed;//以红色为例
    DbGrid1.Canvas.pen.mode:=pmmask;
    DbGrid1.DefaultDrawColumnCell (RectDataColColumnState);
      

  2.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
    if ((State = [gdSelected]) or (State=[gdSelected ,gdFocused])) then
    DbGrid1.Canvas.Brush.color:=clRed;//以红色为例
    DbGrid1.Canvas.pen.mode:=pmmask;
    DbGrid1.DefaultDrawColumnCell (Rect,DataCol,Column,State);
    end;
      

  3.   

    //----------------------------根据状态不同设置不同的颜色------------------------
    procedure TfrmCYSQ.DBGrid1GetCellParams(Sender: TObject; Column: TColumnEh;
      AFont: TFont; var Background: TColor; State: TGridDrawState);
    begin
      if ds.DataSet.FieldByName('SPZT').AsString = '待审批' then
      begin
        Background := DSHP_COLOR;
      end else
      if ds.DataSet.FieldByName('SPZT').AsString = '已审批' then
      begin
        Background := YSHP_COLOR;
      end else
      if ds.DataSet.FieldByName('SPZT').AsString = '未审批' then
      begin
        Background := WSHP_COLOR;
      end;
    end;看看这个有没有帮助!!!这个是根据某一字段的值变化行的颜色,你把它换成当前行就可以了