我使用dbgrid显示学生成绩,我怎么把不及格(分数<60)的学生成绩用红颜色的字显示出来

解决方案 »

  1.   

    在OnDrawDataCell中写:
    procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; 
    Field: TField; State: TGridDrawState); 
    begin 
      if Table1.FieldByName('分数').Value <60 then 
         DBGrid1.Canvas.Font.Color := clRed; 
      DBGrid1.DefaultDrawDataCell(Rect, Field, State); 
    end; 
      

  2.   

    http://dev.csdn.net/article/53/53439.shtm  DBGrid应用全书(一) 
    http://dev.csdn.net/article/53/53440.shtm  DBGrid使用全书(二)
    http://dev.csdn.net/article/53/53441.shtm  DBGrid使用全书(三) 
    http://dev.csdn.net/article/53/53442.shtm  DBGrid使用全书(四)
    http://dev.csdn.net/article/53/53443.shtm  DBGrid使用全书(五)
      

  3.   

    procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    begin
      if(Field.FieldName='分数字段名')and(Field.Value<60) then
        DBgrid1.Canvas.Brush.Color:=$000000FF;end;
      

  4.   

    顺便问一句
    为什么我也是这样改的不过我不是用的CANVAS
    我是直接该的字段的FONT的颜色属性
    但是改出来以后整个DBgrid一直闪烁啊,请问是什么原因呢
      

  5.   

    procedure TForm1.DBGrid6DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
     if Column.Grid.DataSource.DataSet.RecNo Mod 2 = 0 then begin
        DBGrid6.Canvas.Font.Color := clblue;
        DBGrid6.Canvas.Brush.Color := clMoneyGreen;
       end else begin
        DBGrid6.Canvas.Font.Color := clblue;
        DBGrid6.Canvas.Brush.Color := clSkyBlue;
      end;
      if gdSelected in state then begin
         SetBkColor(dbgrid6.canvas.handle,ClYellow);
      end;
      DBGrid6.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
      

  6.   

    if 字段<60  then begin
    dbgrid1.Canvas.Brush.Color:=rgb(246,130,130);
     end;
      with DBGrid1 do
      with Canvas do begin
        if TMyGrid(DBGrid1).Row = MouseCoord(Rect.Left+1, Rect.Top+1).Y then
          Canvas.Brush.Color := RGB(184,193,225);
        DefaultDrawColumnCell(Rect, DataCol, Column, State);
         end;
      if gdselected in state then exit;
     with (sender as tdbgrid).Canvas do
      begin
      pen.color:=$00ff0000;
      moveto(rect.left,rect.bottom);
      lineto(rect.right,rect.bottom);
      end;
    end;