如何使DBgrid中选中的行!以其它颜色显示?

解决方案 »

  1.   

    procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
        Field: TField; State: TGridDrawState); 
        begin
          if gdSelected in state then
          SetBkColor(dbgrid1.canvas.handle,clgreen)
          else
          setbkcolor(dbgrid1.canvas.handle,clwhite);
          dbgrid1.Canvas.TextRect(rect,0,0,field.AsString);
          dbgrid1.Canvas.Textout(rect.Left,rect.Top,field.AsString);
        end;
    找一找就有,不要浪费分了!
      

  2.   

    type TMyGrid = class(TDBGrid);// OnDrawColumnCell事件
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      with DBGrid1 do
      with Canvas do begin
        if TMyGrid(DBGrid1).Row = MouseCoord(Rect.Left+1, Rect.Top+1).Y then
          Canvas.Brush.Color := clRed;
        DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end;
    end;
      

  3.   

    嘿, cainiao000(泥巴) 精典代码,我那个太麻烦,就不用拿来献丑了。可惜我想了半天才做出来。
      

  4.   

    谢谢cainiao000(泥巴)/Devchenxip(天天快乐)!顺便再问一个问题!
    delphi5的DBgrid的DBGrid1DrawDataCell事件什么时候触发的??
    我用Delhi6时DBGrid1DrawDataCell事件有触发,但用Delphi5时DBGrid1DrawDataCell事件无论如何也没有触发!
    求教这是什么问题??
      

  5.   

    同意 Devchenxip(天天快乐) (==============================
    楼主是新手,DrawDataCell在dbgrid的ondrawdatacell事件中填写Delphi5不能触发?不会吧,我用过,可以的。
    可能是DBgrid不在编辑状态吧。
      

  6.   

    我的Delphi5就是没有触发Delphi6就有触发!为什么??
    我只想知道为什么?? 
    至于我的问题cainiao000(泥巴)的方法可解决了!