reportGrid = new DataGridView();
foreach (DataGridViewColumn col in grid.Columns)
{
DataGridViewColumn newCol = new DataGridViewColumn();
newCol = (DataGridViewColumn)col.Clone();
reportGrid.Columns.Add(newCol);
}
I’m trying to mimic some existing code above that works for a DatagridView but for a UltraGrid but not sure how to Clone the column, I looked at CopyFrom as well which works for UltraGridRows.
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);
}
To refactor the InitializeLayout method I mean to extract all the code written for this method (usually formatting columns for display or other one time configuration of the grid) and put everything in a different method directly callable from your code.
Then, when your user press the button to print the grid, initialize the gridReport with the same datasource, call the same common code and perform the specific hiding for the columns on the second grid.
This pseudocode assume you have declared two grid (grdMain with the initial data and grdReport to use for printing) also I assume the presence of a ultraGridPrintDocument to start the printing process