怎么才能使dbgrid的选中行,突出显示?真个选中行颜色不同。请给代码?

解决方案 »

  1.   

    好办,要不你看看人邮的delphi6 编程百例吧。
      

  2.   

    procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
     Field: TField; State: TGridDrawState);
    begin
     if (Rect.Top = TStringGrid(DBGrid1).CellRect(TStringGrid(DBGrid1).col,TStringGrid(DBGrid1).row).top) and (not (gdFocused in State)) then
       Dbgrid1.Canvas.Brush.Color := clRed;
     DBGrid1.DefaultDrawDataCell(Rect, Field, State);
    end;
      

  3.   

    显示选中行的颜色可以用设置dbgrid的option->rowselecded来实现;
      

  4.   

    搞定!设置Dbgrid的DBGrid1DrawDataCell事件中添加如下代码: 
    dbgrid1.Canvas.Font.Color:=clgreen;if gdSelected in state thenSetBkColor(dbgrid1.canvas.handle,clred)elsesetbkcolor(dbgrid1.canvas.handle,clwhite);dbgrid1.Canvas.TextRect(rect,0,0,field.AsString);dbgrid1.Canvas.Textout(rect.Left,rect.Top,field.AsString);