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?
ADAdministrator Syncfusion Team January 19, 2005 01:35 AM
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();
GridControl newGrid = new GridControl(GridModel.LoadBinary(s));
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.