DBGrideh序号问题(50)

  • 主题发起人 主题发起人 380979198
  • 开始时间 开始时间
3

380979198

Unregistered / Unconfirmed
GUEST, unregistred user!
在dbgrideh每行前面加了个序号,那个宽度可不可以改呀,三位的时候就看不到完整的了.
 
用advstringgrid~~
 
可以改的给你一段程序作参考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里面
 
前面这一段不全,我有现成改好的,要的话请留下email
 
简单实用的方法是在数据集里面加一个计算列 xh
 
我的EMAIL:xiaoxingliang1@163.com,谢谢.
 
问题自己已解决了,谢谢各位.
 
多人接受答案了。
 
后退
顶部