Copy/paste problems

Hey guys, I’m using the node class from the flowcharter demo, with a few extra properties… 1 enum, 1 custom class(contains a int and string array), and the rest are just normal strings and int’s. and for some reason, probably the custom types and/or the enum. copy/cut/paste isnt working…cut works(deletes the node) but i cant seem to paste anything. i have some code in place to limit the number of a certain kind of node(and update the counter when that kind is removed or added to the view) but i’m well under that limit, so it “should” not interfere at all. i figure i’ll prolly need to override the copyobject function…but i dont know what i would do inside it.

Your custom class needs to be serializable and deserializable for it to be able to be copied to and pasted from the clipboard.
Make sure the class has the [Serializable] attribute, and that all of its fields are serializable. Or that you have implemented ISerializable and the special constructor.
Whether or not you need to override GoObject.CopyObject depends on the kinds of fields you have added. Fields that are values usually aren’t a problem – the values just get copied. So do references, but sometimes those references need to be updated, or maybe just set to null (e.g. for cached data). You can search the sample code for examples of this.

both the graphnode(inherits GoTextNode) and my custom class are serializable, and all of my fields are values, and i dont espically care if the values stay or not, but it didnt seem to help. i did notice something though, if i copy a node in my app then to a ctrl-v or paste in dev studio(just happens to be the text editor i had up) i paste the text that was in the node. which got me thinking could

n.Background.DraggingObject.DragsNode=true; &nbsp ; n.Background.Selectable=false;

be causing a problem? i tried to remove it for a couple of the nodes and it didnt seem to change anything, but mabye you can think of a reason why it could cause a problem. I have them there to prevent the user from bieng able to drag the background shapes from the pallet to the view( before if you click the shape in the pallett thats all you would drag, you had to click and drag the text to get the actual node to appear in the view).

Well, the paste into a text editor implies that the clipboard does contain a copy of the selected objects. So maybe there’s a problem with deserialization. Try serializing/deserializing programmatically; some code is in Maybe you’ll get an exception deserializing that will point you in the right direction.

It looks like your pulling properties off of the nodes and links and writing them to a xml file, tho i could be wrong. I have save/load functions that work fine, but i havnt added the custom type to it, and it doesnt read the enum value when it loads…i can make the save/load work for both of these cases no problem(read out the arrays, and set the enum value myself), but how can i make the clipboard work with them too?

Hmmm, that topic might be misleading, but the code I was referring to (and that is also in the documentation) is:
Stream ofile = File.Open(“test.graph”, FileMode.Create);
IFormatter oformatter = new <SPAN =highlight>BinaryFormatter();
oformatter.Serialize(ofile, myView.Document);
Stream ifile = File.Open(“test.graph”, FileMode.Open);
IFormatter iformatter = new <SPAN =highlight>BinaryFormatter();
GoDocument doc = iformatter.Deserialize(ifile) as GoDocument;
myView.Document = doc;

ok i linked that code to a random button i have that didnt do anything, and when i run it i get this error

System.Runtime.Serialization.SerializationException: The type Northwoods.Go.GoView in Assembly Northwoods.Go, Version=, Culture=neutral is not marked as serializable.

i removed the public key token portion. the flowcharter example i’m using has a graphView class that inherits goView, so i tried marking that class as serializable and casting the currentGoView to a GraphView but nothing changed, i still got the exact same error. Since it mentions the base GoView class i’m not sure what if anything i can do to fix this problem.



That’s right – GoView, and in fact, System.Windows.Forms.Control, really isn’t serializable.
So it must be that you have a field that refers to the GoView in your GoDocument-derived or GoObject-derived class. That’s a no-no. In fact, you shouldn’t have any fields that refer to any Controls in your document or its objects.

well now i feel dumb…i found a private member of GraphNode that was of type GoView…it was hiding in a minimized region. it was there because i needed to keep the view around to use in formatting functions that i wanted to display in a context menu, when you right clicked on the node. these functions were in the GraphView class, but i had to move them to use in the context menu…i tried replacing my view field with this.view but got a null object exception…i then tried calling the function in GraphView from my event handler in the GraphNode class…but the primary selection was always null. any ideas for a work around, or are we going to have to live without formatting functions in a context menu?

thanks for all your help so far

You’ll note that all the “event” handling methods on GoObject take a GoView argument.
GoObject.View refers to a GoView if and only if the object belongs to a view instead of to a document. Selection handles (GoHandle), for example, only belong to views, not to documents.
By “formatting functions” do you mean text formatting? Why do you need the GoView for that?

formatting functions are like, make same size,make heights same, align left sides, align bottoms, etc… things that change the location/apperance of the node…yeah i did notice that part the OnContextClicked function has it, which is the value i was saving in the field that caused the serializtion problems, but the menuItems need an event handler not just a function or i could pass it that way, here’s part of the menu item declaration

cm.MenuItems[menuIndex-1].MenuItems[0].MenuItems.Add(new MenuItem(“Make Same Size”,new EventHandler(this.MakeSameSize_Command)));
cm.MenuItems[menuIndex-1].MenuItems[0].MenuItems.Add(new MenuItem(“Make Heights Same”,new EventHandler(this.MakeHeightsSame)));

GoObjectEventHandlers didnt work, i didnt think they would but i’ll try anything once. for the functions(make same width, align**, etc…) i’m using the ones included in the flowcharter demo

What’s wrong with defining the MenuItem event handlers the same way they are done in some of the example classes? Take a look at GraphNode.Cut_Command, for example.

I coulda sworn that i posted a reply a little bit later(before yours tho) that said i used the FindView function of the context menu, just like Cut_Command, and it worked fine…wonder what happened to my post, i prolly screwed up and put it in the wrong topic, oh well.

Thanks for all your help.


p.s. this is the best support work and documentation, i’ve ever had for a set of controls i’ve bought, you guys blow away component one, they have some of the worst documentation i’ve ever seen.