none
receiving event when selected node/nodes is changed RRS feed

  • Question

  • Hi,

    I'm trying to write some code, that would perform something using the nodes that are currently selected. To learn when the list of selected nodes is changed I tried using different GViewer's event handlers, like SelectionChanged, MouseClick, Validated and InValidated events. Based on some previous posts, I used the following code to get the selected nodes:

    foreach (var en in networkViewer.Entities)
    {
           if (en.MarkedForDragging && en is IViewerNode)
                  { //got a selected node}

     

    the problem is, that when I receive the event, the newly selected node/nodes is not yet MarkedForDragging. The nodes that have MarkedForDragging = true are those, that were selected before the clicking event.

    What is therefore the event that I could use to get the nodes that are currently selected?

    Thank you for your answer,

    Gregor

    Monday, March 29, 2010 11:53 AM

Answers

  • Hi Gregor,

    Thank you for the helpful example!

    Did you also try this for edges? It seems like the "MarkedForDragging" property is only true when it comes to nodes.

    Thanks in advance,

    Peter

     

    Tuesday, July 20, 2010 12:54 PM

All replies

  • I found the answer myself. The problem is that my MouseClick event is called before DrawingLayoutEditor processes the mouse event and marks the newly selected node. My solution was to postpone processing by dispatching a new event.

     

    I therefore connect the MouseClick event to GraphMouseClick:

    networkViewer.MouseClick += new System.Windows.Forms.MouseEventHandler(GraphMouseClick);

    and my GraphMouseClick looks like this:

    		void GraphMouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
    		{
    			this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate()
    			{ this.updateGraph(); }));
    		}
    

     When the UpdateGraph is then called, I can really find the currently marked nodes:

    void updateGraph()
    		{
    			foreach (var en in networkViewer.Entities)
    			{
    				if (en.MarkedForDragging && en is IViewerNode)
    				{	//got a selected node}
    					IViewerNode node = en as IViewerNode;
    					Debug.WriteLine(node.Node.LabelText);
    				}
    			}
    		}

    Regards,

    Gregor

    Thursday, April 1, 2010 8:24 AM
  • Hi Gregor,

    Thank you for the helpful example!

    Did you also try this for edges? It seems like the "MarkedForDragging" property is only true when it comes to nodes.

    Thanks in advance,

    Peter

     

    Tuesday, July 20, 2010 12:54 PM