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);
}发布于 2012-09-07 04:40:18
为了重构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);
}https://stackoverflow.com/questions/12289115
复制相似问题