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/Paste grid cell with custom data

Hi,

While using a GridControl component I am trying to maintain a reference between each grid cell (GridStyleInfo object) and a underlying cell model of my of design (Class ModelCell).

I have tried to do this by setting a reference in the GridStyleInfo.Tag field of each cell, so it points to the correct underlying ModelCell.

This works well until I use the copy-paste features of the gridControl instance. The problem is that the GridStyleInfo.Tag field is copied along with all the other state in the GridStyleInfo object - thereby overwriting the ModelCell reference of the destination GridStyleInfo.Tag.

In other words: Several GridStyleInfo.Tag fields end up referencing the same ModelCell, while some ModelCells are left unreferenced.

My question is: Is it possible for the copy/paste functions to ignore the GridStyleInfo.Tag field (not likely), or alternatly - does anybody know of a way to maintain such a connection as described above.

Regards, Thomas.

4 Replies

AD Administrator Syncfusion Team September 7, 2006 03:11 PM UTC

I tried to reproduce the problem in this sample, but could not using version 4.2. What version of our libraries are you using?

http://www.syncfusion.com/Support/user/uploads/WindowsApplication20_c7db914d.zip

Are you doing anything different than what the sample does?


TS Thomas Stubbe Teglbjaerg September 8, 2006 12:24 PM UTC

Thank you for the reply !

Sorry i forgot to mention we are using VS. 2005, .NET 2.0 runtime and Essential Studio v. 4.1.0.62 as out development platform.

I''ve tried your example (*) and it runs as I would expect it to, that is; references to ModelCells which are keept in the Tag fields are _not_ copied while performing copy-paste operations in the grid, thereby maintaning the references to the ModelCells correctly.

Further investigation reveals that when the ModelCell class is marked with the [Serializeable] attribute - as our ModelCell class is - the Tag field of the target GridStyleInfo object is set to null after
performing a paste operation.

Is this by design ? If so do you how this is normally handled ?

Do i understand it correctly if i assume the Tag field of the GridStyleInfo object is _not_ to be copied ?

Another thing i''ve noticed playing around with your example, is that GetObjectData() is never called when even though i''ve explicitly told ModelCell to implement ISerializable (ie, ModelCell : ISerializable). This is not the case if ModelCell i _also_ tagged with the [Serializeable] attribute - in that case GetObjectData() is called when pasting into the grid.

- Thomas

(*) I had to comment our the line:

this.gridControl1.SerializeCellsBehavior =
Syncfusion.Windows.Forms.Grid.GridSerializeCellsBehavior.SerializeAsRangeStylesIntoCode;

to make it compile - but figured it wasn''t relevant to the problem at hand.


AD Administrator Syncfusion Team September 9, 2006 09:29 AM UTC

We are still working on this. There may be something broken in the style.ModifyStyle code.

But if all you need to do is to copy/paste values among the cells (and not copy other cell aspects like backcolor, etc.), then you can just tell the grid to copy the text. This will avoid affecting the Tag values which is what you are looking for. You can tell the grid to only copy text using this property setting.

this.gridControl1.CutPaste.ClipboardFlags &= ~GridDragDropFlags.Styles;

If you really do need to copy all style properties except the tag, this can be done by handling an event like ClipboardPaste and doing the work yourself avoiding the library style-paste code.


TS Thomas Stubbe Teglbjaerg September 11, 2006 02:23 PM UTC

Thanx for the tip.

I''ll give that a try.

- Thomas

Loader.
Live Chat Icon For mobile
Up arrow icon