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. Image for the cookie policy date

Copy Gridcontrol

I need to copy a Grid with the style information preserved. Currently i copy the entire grid to a new grid by traversing through the rows. But the cells that are static doesnt appear static in the new grid. (suppose i need to copy a cell that has a button...how do i get that..?) How do i solve this problem? Thanks in advance

9 Replies

AD Administrator Syncfusion Team March 1, 2005 05:22 AM UTC

You can use the Grid.Model.SaveBinary member to store the info into a stream. You can create a new instance of the grid by choosing the constructor with the GridModel parameter. Check also the static LoadBinary member to create the Model instance. Regards, Thomas >I need to copy a Grid with the style information preserved. >Currently i copy the entire grid to a new grid by traversing through the rows. But the cells that are static doesnt appear static in the new grid. (suppose i need to copy a cell that has a button...how do i get that..?) >How do i solve this problem? > >Thanks in advance


AD Administrator Syncfusion Team March 1, 2005 05:28 AM UTC

I am writing a wrapper around the gridcontrol calss where i do not serialize checkbox control... So is there any other option available for copying the grid with style information preserved. >You can use the Grid.Model.SaveBinary member to store the info into a stream. You can create a new instance of the grid by choosing the constructor with the GridModel parameter. Check also the static LoadBinary member to create the Model instance. > >Regards, >Thomas > >>I need to copy a Grid with the style information preserved. >>Currently i copy the entire grid to a new grid by traversing through the rows. But the cells that are static doesnt appear static in the new grid. (suppose i need to copy a cell that has a button...how do i get that..?) >>How do i solve this problem? >> >>Thanks in advance


AD Administrator Syncfusion Team March 1, 2005 08:58 AM UTC

Exactly what is it that you want to do? GridModel.SaveBinary should save any style information pertaining to checkbox cells. It should serialize all style information, and allow you to create an exact copy using GridModel.LoadBinary. Are you saying that this does not work for you? Or, are you saying that you do not want this behavior?


AD Administrator Syncfusion Team March 1, 2005 09:27 AM UTC

Thanks for the reply I create a wrapper around the gridcontrol class where in i serialize textbox classes, but not combobox or other controls... so i need an another way of copying the grid preserving the style information..but not using serialization... >Exactly what is it that you want to do? > >GridModel.SaveBinary should save any style information pertaining to checkbox cells. It should serialize all style information, and allow you to create an exact copy using GridModel.LoadBinary. > >Are you saying that this does not work for you? > >Or, are you saying that you do not want this behavior?


AD Administrator Syncfusion Team March 1, 2005 10:20 AM UTC

I am sorry but I still do not fully grasp what you want to do. Do you want to save some cell styles but not all cell styles for a GridControl? If so, I would create a class with 2 int objects (Row and Col) and 1 GridStyleInfoStore object (Store), and anything thing else you want to save on a cell by cell basis for teh given row and col. Then create an arraylist of these objects, one for each cell you want to save. To get teh GridStyleInfoStore object for a particluar cell, it is a member of the cell style, grid[row, col].Store. This Store property is serializable so you can use the Attribute Serializable on your custom object to facilate using the .NET Framework serialization support to read and write ArrayLists of these custom obejcts. When you are reading the objects back in, you can create a GridStyleInfo object to set as a cell style at row, col by passing the Store object in the GridStyleInfo''s constructor.


AD Administrator Syncfusion Team March 1, 2005 11:04 AM UTC

No, i want a solution that doesnt uses serialization.. without using savebinary method... >I am sorry but I still do not fully grasp what you want to do. > >Do you want to save some cell styles but not all cell styles for a GridControl? > >If so, I would create a class with 2 int objects (Row and Col) and 1 GridStyleInfoStore object (Store), and anything thing else you want to save on a cell by cell basis for teh given row and col. Then create an arraylist of these objects, one for each cell you want to save. To get teh GridStyleInfoStore object for a particluar cell, it is a member of the cell style, grid[row, col].Store. This Store property is serializable so you can use the Attribute Serializable on your custom object to facilate using the .NET Framework serialization support to read and write ArrayLists of these custom obejcts. When you are reading the objects back in, you can create a GridStyleInfo object to set as a cell style at row, col by passing the Store object in the GridStyleInfo''s constructor. >


AD Administrator Syncfusion Team March 1, 2005 01:43 PM UTC

If you want to copy a cell from grid1 to grid2 and have it move all the possible style information over, then you need to make sure the table, row and column styles get set in addition to the cell style. Here is a button handler that will move take cell 2,2 in grid 1 and move it to cell 2,2 in grid 2 in this manner. It uses a helper method to compose the combined style to set into grid 2. Is this what you needed?
private void button1_Click(object sender, System.EventArgs e)
{
	this.gridControl2[2,2] = GetCompositeStyle(2, 2, this.gridControl1);

	this.gridControl2.Refresh();
}

private GridStyleInfo GetCompositeStyle(int row, int col, GridControl grid)
{
	GridStyleInfo style = new GridStyleInfo(grid.TableStyle.Store);
	style.ModifyStyle(grid.ColStyles[col], Syncfusion.Styles.StyleModifyType.Override);
	style.ModifyStyle(grid.RowStyles[row], Syncfusion.Styles.StyleModifyType.Override);
	style.ModifyStyle(grid[row, col], Syncfusion.Styles.StyleModifyType.Override);
	return style;
}


AD Administrator Syncfusion Team March 1, 2005 02:18 PM UTC

No. I want to copy the entire gridcontrol with row headers, col headers to a new grid. If i use the above code for all rows i am not getting it for row headers and col headers. Thanks in advance >If you want to copy a cell from grid1 to grid2 and have it move all the possible style information over, then you need to make sure the table, row and column styles get set in addition to the cell style. Here is a button handler that will move take cell 2,2 in grid 1 and move it to cell 2,2 in grid 2 in this manner. It uses a helper method to compose the combined style to set into grid 2. Is this what you needed? > >
>private void button1_Click(object sender, System.EventArgs e)
>{
>	this.gridControl2[2,2] = GetCompositeStyle(2, 2, this.gridControl1);
>
>	this.gridControl2.Refresh();
>}
>
>private GridStyleInfo GetCompositeStyle(int row, int col, GridControl grid)
>{
>	GridStyleInfo style = new GridStyleInfo(grid.TableStyle.Store);
>	style.ModifyStyle(grid.ColStyles[col], Syncfusion.Styles.StyleModifyType.Override);
>	style.ModifyStyle(grid.RowStyles[row], Syncfusion.Styles.StyleModifyType.Override);
>	style.ModifyStyle(grid[row, col], Syncfusion.Styles.StyleModifyType.Override);
>	return style;
>}
>


AD Administrator Syncfusion Team March 1, 2005 02:54 PM UTC

To copy rowheader and column header styles, you have to copy the styles in the grid.BaseStylesMap. So, you will have to loop through each basestyle in grid.BaseStylesMap and copy it to your new grid. (All this is done for you if you use GridModel.SaveBinary and GridModel.LoaDBinary to copy things).

Loader.
Live Chat Icon For mobile
Up arrow icon