注意:
    dbgrid中可编辑,也就是:dgrowselect为false,现在问题是如何在选中记录时,当前记录行的颜色发生改变,是行而不是单元格。请问如何实现?

解决方案 »

  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.   

    http://www.delphifans.com有例子下载
      

  3.   

    procedure TGridDemo.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
      with TMyDBGrid(Sender) do
     begin
       if DataLink.ActiveRecord=Row-1 then
       begin
         Canvas.Font.Color:=clWhite;
         Canvas.Brush.Color:=$00800040;
       end
       else
       begin
         Canvas.Brush.Color:=Color;
         Canvas.Font.Color:=Font.Color;
       end;
       DefaultDrawColumnCell(Rect,DataCol,Column,State);
     end;end;
      

  4.   

    在开头加上
    type
     TMyDBGrid=class(TDBGrid);
      

  5.   

    crystalreport20xx(自学者)
    的方法可以实现
      

  6.   

    procedure TForm1.DBGrid2DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
    if gdSelected in State then
    begin
    (Sender as TDBGrid).Canvas.Brush.Color := clInfoBk  ;
    (Sender as TDBGrid).Canvas.Font.Color := clred;
    DBGrid2.DefaultDrawColumnCell(Rect,DataCol,Column,State);
    end;end;
      

  7.   

    留下你的EMAIL,我发一个给你。我们有这样的原程序。
      

  8.   

    ;
    http://blog.csdn.net/whbo/articles/232420.aspx
      

  9.   

    procedure TMainForm.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;State: TGridDrawState);
    var i :integer;
    begin
      if gdSelected in State then Exit;
    //定义表头的字体和背景颜色:
        for i :=0 to (Sender as TDBGrid).Columns.Count-1 do
        begin
          (Sender as TDBGrid).Columns[i].Title.Font.Name :='宋体'; //字体
          (Sender as TDBGrid).Columns[i].Title.Font.Size :=9; //字体大小
          (Sender as TDBGrid).Columns[i].Title.Font.Color :=$000000ff; //字体颜色(红色)
          (Sender as TDBGrid).Columns[i].Title.Color :=$0000ff00; //背景色(绿色)
        end;
    //隔行改变网格背景色:
      if Query1.RecNo mod 2 = 0 then
        (Sender as TDBGrid).Canvas.Brush.Color := clInfoBk //定义背景颜色
      else
        (Sender as TDBGrid).Canvas.Brush.Color := RGB(191, 255, 223); //定义背景颜色
    //定义网格线的颜色:
        DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
      with (Sender as TDBGrid).Canvas do //画 cell 的边框
      begin
        Pen.Color := $00ff0000; //定义画笔颜色(蓝色)
        MoveTo(Rect.Left, Rect.Bottom); //画笔定位
        LineTo(Rect.Right, Rect.Bottom); //画蓝色的横线
        Pen.Color := $0000ff00; //定义画笔颜色(绿色)
        MoveTo(Rect.Right, Rect.Top); //画笔定位
        LineTo(Rect.Right, Rect.Bottom); //画绿色的竖线
      end;
    end;