Copying objects problem

I’m using draggable Nodes that drag onto a GraphView canvas (see pic). The green box nodes are “InfoNode8” from the “Demo1” sample and the collapsible blue nodes attached to the bottom of them are “ClassDiagramNode” from the same sample, with some custom buttons on them.


- when I drag a new item, the buttons do not work (see pic, there are multiple buttons on the in the ClassDiagramNode attached to an InfoNode8 node).

- when I drag a new item, the custom variables I added to the InfoNode8 class do not copy over correctly

I think it has to do with overriding the CopyObject() function, which I did, but it still doesn’t seem to work.

CopyChildren is the right method to override. (InfoNode8 isn’t the best sample here… look at InfoNode.)

You need to set new EventHandler for the buttons. … and since those are in a child of a child, you need to override the CopyChildren in the right class.

great thanks. will try that.

That worked. Thanks!

One other quick question. I notice when the custom objects are DeSerialized from file (using GraphDoc.Load) that the buttons are inactive as well. Is there any good sample of loading buttons from file?

Ah… oops. Apparently not. There are 4 GoButtons in Demo1: InfoNode, InfoNode8, ScrollingRecordNode and ScrollingMultiTextNode. The Infonodes use EventHandlers, and don’t appear to work after a save/restore. The Scrolling nodes override OnAction… and do work after being restored.

I'll take a look at the InfoNodes...

Actually, we don’t recommend using serialization for save/restore… Demo1 cheats a bit here.

Is this a prototype, or something you're shipping? Are you planning on moving to XML?

The serialization works perfectly (except for buttons on load) so I’d hate to throw it out. A small set of end users will be making limited using this tool, but there will be no expectation of save files to work between versions (the additional robustness of XML not needed).

I guess I can load through the current serialization method, then have a function run that manually sets all the button events. Seems easier than re-coding the entire load/save functionality?

Yes, it does seem easier. As long as using a saved file in a newer version isn’t an issue…