cxgrid中的 DBTableView 中的数据。通过  select rownum,* from table 
可以选出 rownum,但是现在有一个奇怪的要求,
那就是,要求那行行号的列(rownum)固定,也就是说,可以选择排序,无论怎么排,序号总是从1开始向下排的。
我想不出什么办法来实现了。唉。其实就像Excel的行号一样,Excel的行号根本不会变化,不管你怎么排序,排出来的只是内容。怎么办?

解决方案 »

  1.   

    在cxGrid1DBTableView1 CustomDrawIndicatorCell事件中写代码procedure TForm1.ADOQuery1AfterOpen(DataSet: TDataSet);
    begin
       if DataSet.RecordCount>0 then
        cxGrid1DBTableView1.OptionsView.IndicatorWidth :=
          Canvas.TextWidth(IntToStr(DataSet.RecordCount)) + 4 ;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      ADOQuery1.Active :=not ADOQuery1.Active;
    end;procedure TForm1.cxGrid1DBTableView1CustomDrawIndicatorCell(
      Sender: TcxGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    var
      FValue: string;
      FBounds: TRect;
    begin
      if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
      begin
        FValue :=IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index+1);
        FBounds := AViewInfo.Bounds;
        ACanvas.FillRect(FBounds);
        ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
        InflateRect(FBounds, -1, -1);
        ACanvas.Font.Color := clBlack;
        ACanvas.Brush.Style := bsClear;
        ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
        ADone := True;
      end;
    end;
      

  2.   

    http://community.csdn.net/Expert/topic/4761/4761842.xml?temp=.8880731
      

  3.   

    还是不行,版本是 5.16 我调试了一下 TForm1.cxGrid1DBTableView1CustomDrawIndicatorCell 根本就不执行,为什么?
      

  4.   

    在你先选中cxGrid1TableView1, 再在Object Inspector中自动生成
    CustomDrawIndicatorCell事件代码
      

  5.   

    cxGrid1TableView1->OptionsView-> Inspector设为True
      

  6.   

    我想在序号的右边保留原来indicator中选择时出现的三角符号,怎么实现?