可以改的给你一段程序作参考procedure TCustomDBGridEh.DrawColumnCell(const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState);var //Levi 09-04-02 L: TBrushStyle; //Levi 09-04-02 F: TColor; //Levi 09-04-02 Str: string; //Levi 09-04-02 SerNo : Integer;begin//Levi 09-04-02 begin if (dgIndicator in Options) and FShowSerialNo and Assigned(DataSource.DataSet) then begin L := Canvas.Brush.Style; F := Canvas.Brush.Color; Canvas.Brush.Style := bsClear; if DataSource.DataSet.State = dsInsert then begin if STFilter.Visible then SerNo := MouseCoord(Rect.Left + 1, Rect.Top + 1).Y + DataSource.Dataset.RecordCount - VisibleRowCount else SerNo := MouseCoord(Rect.Left + 1, Rect.Top + 1).Y + DataSource.Dataset.RecordCount - VisibleRowCount + 1; if FFooterRowCount > 0 then SerNo := SerNo + FFooterRowCount + 1; Str := IntToStr(SerNo); if Length(Str) > Length(IntToStr(DataSource.Dataset.RecordCount)) then SetColumnAttributes; end else if (SumList.RecNo > 0) then Str := Format('%d', [SumList.RecNo]); if Canvas.Pixels[(ColWidths[0] - IndicatorWidth + 1), Rect.Bottom - 2] = RGB(64,64,64) then Canvas.Font.Color := clWhite else Canvas.Font.Color := clWindowText; Canvas.TextOut((ColWidths[0] - Canvas.TextWidth(Str) - IndicatorWidth) shr 1, Rect.Bottom - Canvas.TextHeight('0') - 2, Str); Canvas.Brush.Style := L; Canvas.Brush.Color := F; end;//Levi 09-04-02 End if Assigned(OnDrawColumnCell) then OnDrawColumnCell(Self, Rect, DataCol, Column, State);end;procedure TCustomDBGridEh.SetColumnAttributes;var I: Integer;begin for I := 0 to FColumns.Count - 1 do with FColumns do begin TabStops[I + FIndicatorOffset] := {d/} Visible {/} and not ReadOnly and DataLink.Active and Assigned(Field) and not (Field.FieldKind = fkCalculated) and not ReadOnlyField(Field);// ColWidths[I + FIndicatorOffset] := Width; ColWidths[I + FIndicatorOffset] := iif(Visible, Width, iif(dgColLines in Options, -1, 0)); end;// if (dgIndicator in Options) then //Levi// ColWidths[0] := IndicatorWidth; //Levi//Levi 09-04-02 Begin if (dgIndicator in Options) then if FShowSerialNo then begin if Assigned(FColumns.FGrid.DataSource) and Assigned(FColumns.FGrid.DataSource.Dataset) and (FColumns.FGrid.DataSource.Dataset.Active) then if FColumns.FGrid.DataSource.Dataset.State = dsInsert then ColWidths[0] := IndicatorWidth + 4 + Canvas.TextWidth(IntToStr(FColumns.FGrid.DataSource.Dataset.RecordCount + 1)) else ColWidths[0] := IndicatorWidth + 4 + Canvas.TextWidth(IntToStr(FColumns.FGrid.DataSource.Dataset.RecordCount )) else ColWidths[0] := IndicatorWidth; end else ColWidths[0] := IndicatorWidth;//Levi 09-04-02 Endend;有标注的就是我改过的 在DBGridEh.pas里面