Assign custom unique key in a node

Hello, I want a custom key for each node in the diagram.

I’m using a palette with nodes, when i drop a element from the palette to the diagram, i was override the OnNodeAdded method.

I am using a static count that start in 900, the key of the first element dropped in the diagram must be 901 but is 902, the next 904 …

The code of the overrided method is:

Cast node to -> GraphLinksModelNodeData after: the key is asigned a custom key with a 900 value and after increment this counter in one.

Thanks.

Try overriding the model’s MakeNodeKeyUnique method.
You can use the FindNodeByKey method to see if a particular key already has a data object associated with it.

Hello, thanks for the reply.

I was tried the option, but makeNodeKeyUnique doesn’t invoke with the drop of the first element of the palette, but it is launched with de second… of the same type of the palette. If i drop two different elements, this method doen’t execute.

But now i was overrided the OneNodeAdded, but it excute two times, one when drag the element and other when drop, and so when DragSelectingBox is invoked with the mouse.

It might be cleaner to implement a Model.Changed event handler to detect and event with ModelChangedEventArgs.Change == ModelChange.AddedNode.

In this event hander you can see if !(Diagram.CurrentTool is DraggingTool), or if DraggingTool.Source != null. If that’s the case you know it’s a drag from another control.

Thanks for the reply.

I will probe this solution.

we have probed this solution but they choose the override method.
This thread is resolved

Thanks for all. <br =“Apple-interchange-newline”>