向cxgrid里嵌套panel

    有的时候,我们需要对每一个cxgrid数据显示组件上都 有一个'另存'的字段来执行导出操作。  下面的则是主要代码:

var
   n: integer; //此为局变量。
  
procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
  p: Tpanel;
begin
  for i := 0 to  Self.ComponentCount -1 do
  if Self.Components[i] is Tcxgrid then
  begin
    p := TPanel.Create(nil);
    p.Parent := TcxGrid(Self.Components[i]);
    p.Color := clSkyBlue;
    p.Caption := '另存';     
    p.ShowHint := False;
    p.hint := Self.Components[i].Name;
    p.BevelOuter := bvNone;
    p.Name := 'Tpanel' + inttostr(n);
    Inc(n);
    p.OnClick := Button1.OnClick; //这里就是另存下的点击事件,在这里
    p.Left := 2;
    p.Top := 2;
    p.Width := 40;
    p.Height := 17;
  end;
end;

      这样的话那么创建的cxgrid都有了一个'另存'的嵌套字段那么到了这里也仅仅是每一个cxgrid都有一个字段而已,还没有经过处理,它的位置不对,会挡住cxgrid上的第一字段的一部分。而下面还要在cxgrdbtblvwGrid1DBTableView1事件下写一个得到自动编号的代码,此时才算上是比较完整了。

     

procedure TForm1.cxgrdbtblvwGrid1DBTableView1CustomDrawIndicatorCell(
  Sender: TcxGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  value: string;
  Fbounds: TRect;
begin
  Fbounds := AViewInfo.Bounds;
  if (AViewInfo is  TcxGridIndicatorRowItemViewInfo) then
  begin
    ACanvas.FillRect(Fbounds);
    ACanvas.DrawComplexFrame(Fbounds, clBlack, clBlack, [bbottom, bleft, bright], 1);
    value := IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + 1);
    InflateRect(Fbounds, +3, +2);
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawTexT(value, Fbounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;
      
       那么到这个里算得上是比较好的了,就差没有 另存 下的点击事件;而也可以在这里写一个导出到excel表的过程

posted on 2011-06-21 13:40  long6  阅读(730)  评论(0编辑  收藏  举报

导航