We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

gridboundcolumnscollection switching

Thread ID:

Created:

Updated:

Platform:

Replies:

3672 Apr 1,2003 06:48 AM Apr 1,2003 10:05 AM Windows Forms 2
loading
Tags: GridControl
Andy Ullman
Asked On April 1, 2003 06:48 AM

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

Administrator [Syncfusion]
Replied On April 1, 2003 09:04 AM

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.

Andy Ullman
Replied On April 1, 2003 10:05 AM

Thanks works great. Andy

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;