We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Events when manipulating nodes

Thread ID:

Created:

Updated:

Platform:

Replies:

67558 Aug 23,2007 03:13 AM Aug 30,2007 05:47 AM Windows Forms 8
loading
Tags: Diagram
Krzysztof krzyzak
Asked On August 23, 2007 03:13 AM

Hi, i am testing trial version of Diagram component. Before I make a purchase I have a few questions:

1. Is there a possibility to programmatically catch events like:

- Putting node on diagram (drag&drop)
- Moving node in diagram
- Deleting node from diagram
- Attaching head or tail of the link to the node
- Detaching head or tail of the link from the node


2. Can links have custom context menu attached?

3. Can diagram / nodes & links be set to a mode - where they cannot be moved/resized etc. but can be clicked for context menu?


Thank you in advance
Krzysztof

Mohamed Suhaib Fahad A. [Syncfusion]
Replied On August 23, 2007 04:01 PM

Hi,

Thanks for evaluating Syncfusion products. Here's the response to your queries,

1. Is there a possibility to programmatically catch events like:

-> Putting node on diagram (drag&drop
To trigger the diagram drag drop and drag enter events.
this.diagram1.DragEnter += new System.Windows.Forms.DragEventHandler(this.diagram1_DragEnter);
this.diagram1.DragDrop += new System.Windows.Forms.DragEventHandler(this.diagram1_DragDrop);

Please refer the below sample link for this usage:
\\Syncfusion\EssentialStudio\5.1.0.51\Windows\Diagram.Windows\Samples\2.0\Quick Start\DragDrop\cs

-> Moving node in diagram
Just dragging and dropping through mouse we can move the node in a diagram.

-> Attaching head or tail of the link to the node , Detaching head or tail of the link from the node -

Please find the sample from the sample browser for this
\\Syncfusion\EssentialStudio\5.1.0.51\Windows\Diagram.Windows\Samples\2.0\Quick Start\CoolLinks

By selecting the link and deleting it, we can detach the link from the node.

2. Can links have custom context menu attached?
Yes, the link have custome context menu.

Please find the sample from the below link
\\Syncfusion\EssentialStudio\5.1.0.51\Windows\Diagram.Windows\Samples\2.0\Quick Start\ContextMenus\CS

3. Can diagram / nodes & links be set to a mode - where they cannot be moved/resized etc. but can be clicked for context menu?

- This is possible . The Diagram1.AllowDrop prop can be used for preventing node moving. If you want the nodes/links from being edited, you can modify the EditStyle properties associated with each node.

Please let me know if you want any more details.

Regards,
Fahad

Krzysztof krzyzak
Replied On August 24, 2007 01:51 PM


Thank you for quick response!

One more event I'd like to catch: resize of the node. is it also possible?
(I'd like to reposition labels as well as do other bussiness logic processing)

Krzysztof krzyzak
Replied On August 25, 2007 08:15 AM


Hi again.
I think that I do misunderstood something.

For my question:

Is there a possibility to programmatically catch events like:
(...)
Moving node in diagram
(...)

you answered:
-> Moving node in diagram: Just dragging and dropping through mouse we can move the node in a diagram.

The problem is that when I move nodes by mouse (drag&drop?) then DragEnter and DragDrop events are not raised.
Should I use some different events or should I set some properties to get these events to be raised?


To the other part of my question - about events raised when link is attached/detached you referred me to CoolLinks example.

That example also does not show the events I need.

What I need to know is not how to move or attach links but how to programmatically catch this event when it occurs.


Mohamed Suhaib Fahad A. [Syncfusion]
Replied On August 27, 2007 07:11 AM

Hi,

I had thought that you were asking about preliminary details in diagram. Please look at the following details for your queries,

Query 1 - Moving node in a Diagram

Please refer the following code snippets which illustrates the above:

((DocumentEventSink)model1.EventSink).PinPointChanging += new PinPointChangingEventHandler(Form1_PinPointChanging);
void Form1_PinPointChanging(PinPointChangingEventArgs evtArgs)
{
MessageBox.Show("PinpointChanging event is fired"+"\n"+ "Node name: "+evtArgs.NodeAffected.Name.ToString());
}

This event will raise at the start of the location change, likewise you can check for PinPointChanged event for checking it after the node is moved to a particular location.

Query 2 - How to programmatically catch this event when a link is attached/detached ?

This is can be achieved by ConnectionChanged event.

this.diagram1.Model.EventSink.ConnectionsChanged += new CollectionExEventHandler(EventSink_ConnectionsChanged);

In the ConnectionChanged event, you can check whether the selected connector has FromNode or ToNode. If yes, link was attached to nodes, else detached from the nodes.

if (evtArgs.Element is OrthogonalConnector)
{
OrthogonalConnector conn = evtArgs.Element as OrthogonalConnector;
if (conn.FromNode== null || conn.ToNode == null )
MessageBox.Show("Connector is detached from the nodes");
else
MessageBox.Show("Connector is attached to the nodes");
}

Please let me know if this helps you out.

Regards,
Fahad

Krzysztof krzyzak
Replied On August 27, 2007 04:40 PM

Thank you. That events were what I needed.

In your snippet there is a fragment:
if (evtArgs.Element is OrthogonalConnector)
I used LineConnector and observed that element is rather EndPoint type (TailEndPoint/HeadEndPoint) than LineConnector object. Is that your mistake or LineConnector is treated differently?

One outstanding problem is that when a link is attached to a node and the node is deleted by user then ConnectionsChanged is not raised despite the link is no longer connected.
Is it possible to have ConnectionChanged raised?

Next one is that I want to know which node the link is connected to/disconnected from. To determine this I used Owner property. Is that right way or is there a better one?

Mohamed Suhaib Fahad A. [Syncfusion]
Replied On August 28, 2007 09:48 AM

Hi,

Sorry for the inconvenience. The event was actually "NodeCollectionChanged" not the one mentioned in the previous section. Here's the code snippet for your queries,

-> When a node is deleted what event is raised??

Please use the following code snippet for checking if any node/connector/other objects related to nodes are changed in the node collection. Use the "ChangeType" enum value to identify the type of change.

void EventSink_NodeCollectionChanged(CollectionExEventArgs evtArgs)
{
if (evtArgs.ChangeType == CollectionExChangeType.Remove && evtArgs.Element is LineConnector)
{
MessageBox.Show("removed");
LineConnector conn = evtArgs.Element as LineConnector;
MessageBox.Show("From node is " + conn.FromNode.ToString());
MessageBox.Show("To node is " + conn.ToNode.ToString());
}
else if (evtArgs.ChangeType == CollectionExChangeType.Insert && evtArgs.Element is Node)
{
MessageBox.Show(((Node)evtArgs.Element).Name);
}
}

-> Need to know which node is connected to which link.

This can be resolved by getting the connector object and then accessing the "FromNode" and "ToNode" properties, to know which node is connected.

Please refer to the below link which illustrates for the above queries,

http://websamples.syncfusion.com/samples/Diagram.Windows/F67558/main.htm

Please let me know if this helps you out.

Thanks,
Fahad

Krzysztof krzyzak
Replied On August 28, 2007 01:29 PM

Hi,
You didn't understand my last post. I didn't ask what event is raised when node is deleted. My problem is a liitle more complex.

I will try to give you an example:
1. Imagine, that a line connector is green when it is connected to a node and must be red when it is not connected.

2. Imagine that user does following steps:
a) creates a node
b) creates a link (it is red initially)
c) attaches a link to a node - you catch ConnectionsChanged event and change link color to green
d) deletes node (NOT the link) - the NodeCollectionChanged is raised but ConnectionsChanged not.

3. Question: How can you know that the link should change the color to red in step d).

Second - different thing:
You suggest to use FromNode/ToNode properties. When the link is being detached - the ToNode/FromNode accessible from event args is null, right? How can I know which node is it detached from?


Thanks!
krzysztof

Mohamed Suhaib Fahad A. [Syncfusion]
Replied On August 30, 2007 05:47 AM

Hi,

The ConnectionsChanged event will trigger only when connection with respect to link is changed (inserted, removed / set).

Q1- How to know the link should change the color to red?

There is no method to detect the color changes of the link. Its designed like that.

You must use the NodesCollectionChange event to know if any object(Node) is deleted from the nodes collection. That is why i had specified about this event instead of ConnectionsChanged event in my last update.

Q2- Detach/Attach nodes?

Yes, the FromNode/ToNode would be null after the ConnectionsChanged event is raised. We dont have a ConnectionsChanging event.

Thanks for suggesting this valuable feature of "Raising event when link is attached/detached" to enhance our product. We will log it as a feature request and notify our development team. We will implement this feature in our forthcoming new version releases or service pack releases. We usually have a time frame of atleast three months between releases. The feature implementation would also greatly depend on the factors like product design, code compatibility and complexity. We will get back to you once the feature is implemented.

As a workaround we have a sample created which uses a Hashtable to maintain the list of FromNode/ToNode. This can be used to find the attached/detached nodes. Please download the modified sample from the following location,

http://websamples.syncfusion.com/samples/Diagram.Windows/F67558/main.htm

Please modify the sample according to your needs. It does finds the detached and attached nodes.

Let me know if this helps you out.

Regards,
Fahad

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;