Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1445
How can I get a copy of a grid?
posted

I want to get a copy of a grid but not have any references tied to the orginal grid.

When I do this...

Infragistics.Win.UltraWinGrid.

 

UltraGrid grdExport = this.grdFormGrid;

I want to be able to edit the columns in grdExport without effecting the grid on the form. If I do this...

grdExport.DisplayLayout.Bands[0].Columns[0].Hidden = true;

it will hide the column on both, even though I want it to remain visible on the othe grid.

 

I think I figured out the display, but now I want to copy the rows. I can't believe I have to do this a 2 step process. There is no clone or copy function? My rows in my grid are a mix of bound and unbound columns.

  • 469350
    Offline posted

    Hi,

    apalcer said:
    UltraGrid grdExport = this.grdFormGrid;

    This code does not create a copy of anything, it's just creating a new variable that references the same object. So I'm not sure what you mean by "it will hide the column on both". Both what?

    What you need to do is create a new grid object using the constructor. You will have to bind the new grid to a data source. You could use the same data source, but this would mean that changing the data in one grid would update the other, so you may want to create a new data source for the new grid, as well.

    There's no Clone method on the grid, so you would need to handle the copying of any grid-level properties from one grid to the other yourself. You probably would not want to copy all properties, anyway because it wouldn't make sense. For example, you would not want to copy the Name of the grid or it's Location.

    Once you bind the new grid to a DataSource with the same structure as the old grid, you could copy most of the grid's important settings over to the new grid using the grid.DisplayLayout.CopyFrom method. You just pass in the DisplayLayout of the original grid.