This is a migrated thread and some comments may be shown as answers.

[Solved] Deep Copy

3 Answers 239 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Igon
Top achievements
Rank 1
Igon asked on 08 Jan 2009, 01:44 PM

Hi ,
Is there a way for creating a deep copy of a RadGrid.

I have a RadGrid that is set at design time , so  in the run time I want to create a deep copy of the Grid
so I can change the columns, operate with the values etc.  so at the end  the originally grid is not changed.

It is nice if this some how works automatically , because I have over 100 Grids, its not wise to make separate code for every Grid.


Example:
   it should work something like this :

RadGrid rgCopy =  new RadGrid();
rgCopy =  createCopy(rgOriginal);


Is this possible ?

Regards

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Jan 2009, 10:52 AM
Hi Igon,

I tried following code snippet for creating copy of the RadGrid. I created a sample datatable and filled it with Radgrid row values, then  set the sample datatable as the DataSource of the newly created RadGrid. Hope this will help you.

CS:
RadGrid rad = new RadGrid(); 
DataTable dtSample = new DataTable(); 
GridTableView dt = RadGrid1.MasterTableView; 
for(int i=0; i<dt.Columns.Count;i++) 
      dtSample.Columns.Add(new DataColumn(dt.Columns[i].HeaderText)); 
for (int j = 0; j < dt.Items.Count; j++) 
      DataRow row = dtSample.NewRow(); 
      for (int z = 0; z < dtSample.Columns.Count; z++) 
      { 
           row[z] = dt.Items[j][dt.Columns[z]].Text; 
      } 
      dtSample.Rows.Add(row); 
rad.AutoGenerateColumns = true
rad.DataSource = dtSample; 
rad.DataBind(); 
Panel1.Controls.Add(rad); 

Thanks,
Princy.
0
Igon
Top achievements
Rank 1
answered on 09 Jan 2009, 02:48 PM
Hi

The Solution is partial ok , because I want to copy not just the data
but also all Properties
0
Emeleen
Top achievements
Rank 1
answered on 13 May 2009, 10:19 PM
Hi Princy,

I used the code above and it only copied the bound columns. How can i make it
copy the Template columns?
Thanks!

Emeleen
Tags
Grid
Asked by
Igon
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Igon
Top achievements
Rank 1
Emeleen
Top achievements
Rank 1
Share this question
or