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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

gridboundcolumnscollection switching

Thread ID:

Created:

Updated:

Platform:

Replies:

3672 Apr 1,2003 11:48 AM UTC Apr 1,2003 03:05 PM UTC WinForms 2
loading
Tags: GridControl
Andy Ullman
Asked On April 1, 2003 11:48 AM UTC

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 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.

Andy Ullman
Replied On April 1, 2003 03:05 PM UTC

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.

Warning Icon 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.Close Icon

;