How do I get the selected nodes in a diagram


what I was to do is apply a function to all the nodes selected, say change the back colour of the node

e.g. I want to do something like this

foreach (Node n in Diagram1.Model.Nodes)
{
     if (n.Selected)
     {
          n.BackColor = Color.Blue;
     }
}

5 Replies

NG Naganathan Ganesh Babu Syncfusion Team May 21, 2018 09:14 AM UTC

Hi David, 
 
Thanks for contacting Syncfusion support. 
 
In order to achieve your requirement, we suggest you to use Node.FillStyle’s “Color” property to define the color of the Node. please refer to the below modified code. 
 
Modified code: 
 
[C#] 
 
Your Code 
Modified code 
foreach (Node n in Diagram1.Model.Nodes) 
{ 
     if (n.Selected) 
     { 
          n.BackColor = Color.Blue; 
     } 
} 
 
foreach (Node n in Diagram1.Model.Nodes) 
{ 
     if (n.Selected) 
     { 
          (n as FilledPath).FillStyle.Color = Color.Blue; 
     } 
} 
 
 
Regards, 
 
Naganathan K G 



DJ David Jackson May 21, 2018 09:48 AM UTC

Hi I think you misunderstand. I can find no way to actually get the selected nodes

Contrary to the documentation the IsSeleced property for a node does not exist

Dave 


NG Naganathan Ganesh Babu Syncfusion Team May 21, 2018 10:04 AM UTC

Hi David, 
 
Sorry for the inconvenience caused. 
 
We don’t have in-built options to identify whether a node has been selected or not. However, we can use Diagram.View.SelectionList’s “Contains()” method to identify whether the node has been added in selection list. Please refer to the below modified code example. 
 
Code example: 
 
[C#] 
 
foreach (Node node in diagram1.Model.Nodes) 
{ 
if (diagram1.View.SelectionList.Contains(node)) 
 (node as FilledPath).FillStyle.Color = Color.Blue; 
}  
 
Regards, 
 
Naganathan K G 



DJ David Jackson May 21, 2018 04:57 PM UTC

Thank you. I have just tried that and its working


NG Naganathan Ganesh Babu Syncfusion Team May 22, 2018 05:56 AM UTC

Hi David,

Thanks for your update.
 

We are happy to hear that your problem is resolved. Please let us know if you need any further assistance.

Regards,
 

Naganathan K G
 


Loader.
Up arrow icon