I have a griddataboundgrid with a DataTable as its source. I do some customizations on the gridboundcolums that are automatically created. At a certain point, I clone the DataTable, and this copy becomes the datasource of the datagrid. I want the changes I made to the gridboundcolumns to remain on the datagrid (since the table structure is identical).
I tried saving a reference to the gridboundcolumnscollection, setting the datasource property to the cloned table, and then setting the gridboundcolumnscollection property back to my saved reference. No effect (the gridboundcolumns are reinitialized). I also tried several different approaches involving cloning the collection and adding cloned gridboundcolumns one at a time (thinking that the datagrid keeps reusing the gridboundcolumns instead of instantiating new ones). Same problem. Any ideas?
ADAdministrator Syncfusion Team April 1, 2003 09:04 AM
//set the datasource to generate the internal columns
this.gridDataBoundGrid1.DataSource = dt;
//modify the internal columns somehow...
GridBoundColumn gbc = this.gridDataBoundGrid1.Binder.InternalColumns;
gbc.HeaderText = "Column 1";
//save the internal columns
int count = this.gridDataBoundGrid1.Binder.InternalColumns.Count;
GridBoundColumn gbcs = new GridBoundColumn[count];
for(int i = 0; i < count; ++i)
gbcs[i] = this.gridDataBoundGrid1.Binder.InternalColumns[i];
//add the save columns as GridBoundColumns
You have to save the internal columns to be able to later use them as the first time a column is added to GridBoundColumns, the InternalColumns are zapped.
Attached is a little sample that rebinds the grid to a table.Clone when you press the button without losing the title set in teh grid bound column.