Profile Picture

EventSinkService NodeInserted Shape as Group

Posted By Volvick Derose 14 Years Ago
Author
Message
Volvick Derose
Posted 14 Years Ago
View Quick Profile
Forum Guru

Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 71, Visits: 1

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

    }

}

 



Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Volvick,

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



Best Regards,
Nevron Support Team



Volvick Derose
Posted 14 Years Ago
View Quick Profile
Forum Guru

Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 71, Visits: 1
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

Volvick Derose
Posted 23 Years Ago
View Quick Profile
Forum Guru

Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 71, Visits: 1
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

Volvick Derose
Posted 23 Years Ago
View Quick Profile
Forum Guru

Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 71, Visits: 1
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

Volvick Derose
Posted 23 Years Ago
View Quick Profile
Forum Guru

Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 71, Visits: 1
Sorry that was my problem, I forget to name the group. After naming it, everything works fine



Similar Topics


Reading This Topic