我把一個數據集的數據分別放入兩個dbgrid中,我想實現在兩個dbgrid中當前資料背景色突出表示是當前筆資料。

解决方案 »

  1.   

    type
      {expose private & protected properties & methods}
      TFriendly = class(TCustomDBGrid);procedure TFormSetting.DBGrid13DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
      with TFriendly(Sender) do
      begin
        {Get active record within grids TDataLink. The active record will be
         the current record in the dataset. Check against Row that we are
         trying to Draw, -1 to offset the column headings within grid.}
        if TDataLink(DataLink).ActiveRecord = Row - 1 then
        begin
          with Canvas do
          begin
            {set grids canvas to win highlight colour}
            Brush.Color := $00C0FFFF; //clHighlight;
            Font.Color := clBlack;
            {now redraw the cell, but highlighted}
            DefaultDrawColumnCell(Rect, DataCol, Column, State);
          end;
        end;
      end;
     end;