gridboundcolumnscollection switching

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? Thanks Andy

2 Replies

AD Administrator Syncfusion Team April 1, 2003 02:04 PM UTC

Try this.
//set the datasource to generate the internal columns	
this.gridDataBoundGrid1.DataSource = dt;

//modify the internal columns somehow...
GridBoundColumn gbc = this.gridDataBoundGrid1.Binder.InternalColumns[1];
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
this.gridDataBoundGrid1.GridBoundColumns.AddRange(gbcs);
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.


AU Andy Ullman April 1, 2003 03:05 PM UTC

Thanks works great. Andy

Loader.
Up arrow icon