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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Copying a Grid

Thread ID:





23749 Jan 19,2005 01:08 AM UTC Jan 19,2005 06:35 AM UTC WinForms 1
Tags: GridControl
Sue Harris
Asked On January 19, 2005 01:08 AM UTC

Hi, I''ve got a grid which is being populated using the virtual QueryCellInfo, QueryColCount etc methods. I''d like to take a copy of the grid into another non-virtual grid. What would be the best way to do this? Thanks, Sue

Administrator [Syncfusion]
Replied On January 19, 2005 06:35 AM UTC

There are basically 2 types of information you will need to copy. One is the actual data, and the other are things stored in the GridModel like ColWidths, etc. To copy the GridModel, you can serialize it to a memorystream and then create a new instance from the serialized data. System.IO.MemoryStream s = new System.IO.MemoryStream(); oldGrid.SaveBinary(s); GridControl newGrid = new GridControl(GridModel.LoadBinary(s)); s.Close(); The quickest way to handle teh actual data is to do it directly through your external datasource, and not try to use the oldGrid. The reason is that if you go through the oldGrid and use an indexer on this grid to retrieve the data, events (such as QueryCellInfo that actually gets the data) will be raised. If you access your datasource directly, then these events will be avoided which normally makes things much faster. To put the data into your new grid, if your datasource is something recognized by the grid.PopulateValues method, you should use that method. If not, you can loop through your datasource and call grid.SetCellInfo to set the values into the grid. Make sure you use the overload that has dontRaiseSaveCellInfo and pass this as true. Or, you can just directly set the values into the GridData object yourself.
newGrid.RowCount = rowsInDataSource;
newGrid.ColCount = colsInDataSource;
for(int row = 1; row <= rowsInDataSource; row++)
	for(int col = 1; col <= colsInDataSource; col++)
		object o = GetValueFromYourDataSource(row, col);
		if(o != null)
			GridStyleInfo style = new GridStyleInfo();
			style.CellValue = o;
			newGrid.Data[row, col] = style.store;


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon