我现在用DBGRID显示库存里所有的数据,想控制每条记录根据不同的数量显示红色
例如:
  1<=20 显示红色
  2<=10 显示红色
  3<=100 显示红色

解决方案 »

  1.   


    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使用全书(五)  
      

  2.   

    把下面一段代码稍加修改写在DrawColumnCell:
    with (Sender as TDBGrid).Canvas do
     begin
     if TryStrToFloat((Sender as TDBGrid).Columns.Items[DataCol].Field.AsString,f) then
      begin
       if f < 0 then
       begin
        MoveTo(Rect.Right, Rect.Top);
        FillRect(Rect);
        Font.Color := clRed;
        TextOut(Rect.Left,Rect.Top,(Sender as TDBGrid).Columns.Items[DataCol].Field.AsString);
       end;
      end;
      

  3.   

    在DBGrid的OnDrawColumnCell事件中if AdoQuery1.FieldByname('价格').AsFloat>=2000 then
      begin
        DBGrid1.Canvas.Font.Color:=clRed;
        DBGrid1.Canvas.Brush.Color:=clWhite;
      end;
    DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);上面的代码是在字段“价格”里的值大于等于2000的时候,整行字为红色
    如果只想让价格那一列成为红色
    把条件改一下即可
    假设“价格”字段在DBGRID中的第3列
    则条件为
    if (DataCol=2) and (AdoQuery1.FieldByname('价格').AsFloat>=2000) then