Nevron Forum

EventSinkService NodeInserted Shape as Group

https://www.nevron.com/Forum/Topic4082.aspx

By Volvick Derose 1 - Monday, December 31, 2001

Sorry that was my problem, I forget to name the group. After naming it, everything works fine
By Volvick Derose 1 - Monday, December 31, 2001

While it works, but there are still issues and it crashes. It looks like in the eventsink service node inserting it is not possible to do something like this

private void EventSinkService_NodeInserted(NChildNodeEventArgs args)
{
NShape shapeName = args.Child as NShape;
NGroup groupName = args.Child as NGroup;

Then

if (hapeName ==)

and

if (groupName ==)

It looks like it can only be one, not both
By Volvick Derose 1 - Monday, December 31, 2001

This solution seems to work, but there must be a better way to do it.

I provide a unique ID to the group that is added to the library before adding it

for instance, before added the group to the library

shapeGroup.Tag = uniqueID;

then in the eventsink, I use this only

NShape shapeName = args.Child as NShape;

but refer to the group by the tag ID

like

if(shapename.Tag == uniqueID)//group unique id
By Volvick Derose 1 - Monday, August 30, 2010

When I add shape to my library as shape or composite shape, works fine, but does not work for group added

NGroup myShape = args.Child as NGroup;//this is a group that was added to the library

then I go

if (myShape.Name == "group name")
{

MessageBox.Show("message");
}

does not work
By Nevron Support - Tuesday, August 31, 2010

Hi Volvick,

please, elaborate what are you trying to do and post more code so that we can assist you better.

By Volvick Derose 1 - Tuesday, August 31, 2010

I have talking about the following example from the knowledgebase

I have created a diagram that uses a library browser. I can drag and drop several object from the library to the document. The task that I need is for an event to fire on the creation of a new shape, and also an event when an already created shape is altered/deleted. I am having trouble finding a way to hook into these events. These are object that will be created during the run-time of the program. I saw examples for adding changed value events for programmatically created object, but I need for these event handlers to apply to all object created from the library browser. Any information on this would be greatly appreciated.

 

Answer:

 

The NodeInserted and NoderRemoved events of the document event sink service will be fired whenever a node has been inserted or removed from the document regardless of the way in which this was done. You can subscribe for this events with the following code:

document.EventSinkService.NodeInserted += new ChildNodeEventHandler(OnNodeInserted);

document.EventSinkService.NodeRemoved += new ChildNodeEventHandler(OnNodeRemoved);

 

private void OnNodeInserted(NChildNodeEventArgs args)

{

    if (args.Child is NShape)

    {

        // do something when a shape is added

    }

}

 

Assume that I have something like this

 

NGroup myShape = args.Child as NGroup;//this is a group that was added to the library

then I go

if (myShape.Name == "group name")
{

MessageBox.Show("message");
}

It only works for the following

 

NShape myShape = args.Child as NShape;//this is a group that was added to the library

then I go

if (myShape.Name == "group name")
{

MessageBox.Show("message");
}

Does not work if myShape is a group as described above


 

 

private void OnNodeRemoved(NChildNodeEventArgs args)

{

    if (args.Child is NShape)

    {

        // do something when a shape is removed

    }

}