如何克隆UltraGridColumn(Infragistics)


reportGrid = new DataGridView();
foreach (DataGridViewColumn col in grid.Columns)
{
    DataGridViewColumn newCol = new DataGridViewColumn();
    newCol = (DataGridViewColumn)col.Clone();
    reportGrid.Columns.Add(newCol);
}

我正在尝试模仿上面的一些现有代码,这些代码适用于 DatagridView,但适用于 UltraGrid,但不确定如何克隆列,我也查看了适用于 UltraGridRows 的 CopyFrom。

 foreach (UltraGridColumn col in grid.DisplayLayout.Bands[0].Columns)
 {
      UltraGridColumn newCol = new UltraGridColumn();  //Errror here as well
      //newCol = (UltraGridColumn)col.Clone();
      newCol.CopyFrom(col);
      reportGrid.DisplayLayout.Bands[0].Columns.Add(newCol);
 }

为了重构 InitializeLayout 方法,我的意思是提取为此方法编写的所有代码(通常格式化列以显示或网格的其他一次性配置(,并将所有内容放在可从代码中直接调用的不同方法中。

然后,当用户按下按钮打印网格时,使用相同的数据源初始化 gridReport,调用相同的公共代码并对第二个网格上的列执行特定的隐藏。

这个伪代码假设你已经声明了两个网格(grdMain 与初始数据和 grdReport 用于打印(,我也假设存在一个 ultraGridPrintDocument 来启动打印过程

private void gridMain_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
    CommonInitializeLayout(gridMain, e);
}

private void CommonInitializeLayout(UltraWinGrid grd, InitializeLayoutEventArgs e)
{
   UltraGridBand b = e.Layout.Bands[0];
   // Now do the customization of the grid passed in, for example....
   b.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
   b.Override.AllowAddNew = AllowAddNew.No;
   b.Override.NullText = "(Not available)";
   b.Columns["CustName"].Header.Caption = "Customer Name";
   ....... etc ....
}
private void cmdMakeReport_Click(object sender, EventArgs e)
{
    // This assignment will trigger the InitializeLayout event for the grdReport
    grdReport.DataSource = grdMain.DataSource;
    // Now the two grids have the same columns and the same data 
    // Start to hide the columns not desired in printing
    grdReport.DisplayLayout.Bands[0].Columns["CustID"].ExcludeFromColumnChooser =
                                                             ExcludeFromColumnChooser.True 
    grdReport.DisplayLayout.Bands[0].Columns["CustID"].Hidden = true;
    // .... other columns to hide.....
    // Now print the grdReport
    ultraGridPrintDocument.Grid = grdReport;
    ultraGridPrintDocument.Print();
}
private void gridReport_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
    CommonInitializeLayout(griReport, e);
}

相关内容

  • 没有找到相关文章

最新更新