如何在用鼠标点选dbgrid中的某一行时该行显示某种颜色,点选另外一行时该也显示另外一种颜色,但刚才那行颜色恢复?

解决方案 »

  1.   

    procedure Tclwhf.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
     var
          C1,   C2:   TColor;
      begin
          if   gdSelected in   State   then
          begin
              with   TDBGrid(Sender).Canvas   do
              begin
              C1   :=   Brush.Color;
              C2   :=   Font.Color;          Brush.Color   :=   ClRed;//红底
              Font.Color   :=   Clyellow;//黄字          TDBGrid(Sender).DefaultDrawColumnCell(Rect,   DataCol,   Column,   State);
              Brush.Color   :=   C1;
              Font.Color   :=     C2   ;
              end;
          end; end;
    这个是红底黄字1~
      

  2.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if DataSource1.DataSet.FieldByName('id').AsInteger mod 2 = 0 then
        DBGrid1.Canvas.Brush.Color := clred 
      else
        DBGrid1.Canvas.Brush.Color := clYellow;
       DBGrid1.DefaultDrawColumnCell(rect,datacol,column,state);
    end;
      

  3.   

    就是选择一整行阿
    你把DBgrid的options里面dgediting选中就可以了
      

  4.   

    借贵弟一用!谢谢
    DBGrid高手请帮帮我呀!
    http://community.csdn.net/Expert/topic/5377/5377515.xml?temp=.7863123
      

  5.   

    其实我的用意是这样的!
    向数据库更改完数据之后,按“提交”按钮,然后要在dbgrid中高亮显示我刚才修改过的那条记录!