Bind nodes in DocumentExplorer

I would like to bind nodes (in the DocumentExplorer) to EditControl. Each node has properties in the propertyEditor. For instance, with the following nodes structure in the DocumentExplorer control:

Model
   Nodes(3)
      - node1
      - node2
      - node3

node1 has custom property with values v1, v2 and v3 in the PropertyEditor.  What I would like to do is, when I click on node1 in the DocumentExplorer, v1, v2 and v3 are printed to the EditControl. Likewise, if node2 is clicked, the corresponding values in the PropertyEditor will be Printed to EditControl.

The printing format in the EditControl is (eg. node1 is clicked):
start node1;
Value1 is v1;
Value2 is v2;
Value_n is v_n;
end node1;

... etc

How can I achieve this?




15 Replies

NG Naganathan Ganesh Babu Syncfusion Team February 8, 2018 12:23 PM UTC

Hi Allen, 
 
We have created a sample to achieve your requirement. Please refer to the below attached sample and code example. 
 
Code example: 
 
[VB] 
 
AddHandler diagram1.EventSink.SelectionListChanged, AddressOf EventSink_SelectionListChanged 
 
Private Sub EventSink_SelectionListChanged(ByVal evtArgs As CollectionExEventArgs) 
                                    If evtArgs.ChangeType = CollectionExChangeType.Insert AndAlso TypeOf evtArgs.Element Is CustomBitmapNode Then 
                                                Dim node As CustomBitmapNode = TryCast(evtArgs.Element, CustomBitmapNode) 
                                                Dim v1 As String = node.Car.ToString() 
                                                Dim v2 As String = node.Price 
                                                Dim v3 As String = node.FilePath 
                                                Dim BasePath As String = Path.GetDirectoryName(Application.ExecutablePath) 
                                                'Refresh the File content 
                                                If File.Exists(BasePath & "\form1.txt") Then 
                                                            File.WriteAllText(BasePath & "\form1.txt", String.Empty) 
                                                End If 
                                                Dim writer As New StreamWriter(BasePath & "\form1.txt", True) 
                                                writer.WriteLine("start " & node.Name) 
                                                writer.WriteLine("Car:" & v1) 
                                                writer.WriteLine("Price:" & v2) 
                                                writer.WriteLine("File path:" & v3) 
                                                writer.WriteLine("end " & node.Name) 
                                                writer.Close() 
 
                                                Me.editControl1.LoadFile(BasePath & "\form1.txt") 
                                    Else 
                                                Me.editControl1.Close() 
                                    End If 
                        End Sub 
 
Sample: 
 
 
Regards, 
 
Naganathan K G 



AL Allen February 17, 2018 09:55 AM UTC

Dear Naganathan,
Thank you so much for your help. May I ask your further help for a minor touch.  I notice that the EditControl doesn't update when I change the car type from the PropertyEditor. How can I update the EditControl when the car type is changed?
I was also trying to print a text to the Edit control when a node is clicked in the Document Explorer. For now, the EditControl can be updated only when we select the Node on the Diagram sheet (i.e, unselect and then select)
Once again, thank you


AL Allen February 17, 2018 11:36 AM UTC

Dear Naganathan, I managed to update editcontrol with propertyvalue canged event.

So please disregard this question.

Thank you








NG Naganathan Ganesh Babu Syncfusion Team February 19, 2018 04:46 AM UTC

Hi Allen, 
  
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   



AL Allen February 19, 2018 07:23 AM UTC

Dear Naganathan,
Thank you.  I would like to click a node within the DocumentExplorer, which programmatically selects the node on the diagram sheet. When then node is selected, a msgBox shows up with the selected node name.
Can you please help on this? 


NG Naganathan Ganesh Babu Syncfusion Team February 20, 2018 04:56 AM UTC

Hi Allen, 
In order to achieve your requirement, we suggest you to use DocumentExplorer’s “AfterSelect” event to select the node from the Diagram. Please refer to the below code example and sample. 
Code example: 
[VB] 
AddHandler DocumentExplorer1.AfterSelect, AddressOf documentExplorer1_AfterSelect 
Private Sub documentExplorer1_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs) 
            If TypeOf e.Node.Tag Is Node Then 
                Dim nodeTemp As Node = TryCast(e.Node.Tag, Node) 
                If nodeTemp IsNot Nothing Then 
                    If nodeTemp.Visible AndAlso nodeTemp.Root.Equals(Me.diagram1.Model) Then 
                        diagram1.View.SelectionList.Clear() 
                        diagram1.View.SelectionList.Add(TryCast(e.Node.Tag, Node)) 
                        diagram1.Focus() 
                    End If 
                End If 
            End If 
        End Sub 
Sample: 
Regards, 
Naganathan K G  



NG Naganathan Ganesh Babu Syncfusion Team February 20, 2018 05:01 AM UTC

Hi Allen,  
 
Please ignore previous update. 
 
In order to achieve your requirement, we suggest you to use DocumentExplorer’s “AfterSelect” event to select the node from the Diagram. Please refer to the below code example and sample.  
 
Code example:  
 
[VB]  
 
AddHandler DocumentExplorer1.AfterSelect, AddressOf documentExplorer1_AfterSelect  
 
Private Sub documentExplorer1_AfterSelect(ByVal sender As ObjectByVal e As TreeViewEventArgs)  
            If TypeOf e.Node.Tag Is Node Then  
                Dim nodeTemp As Node = TryCast(e.Node.Tag, Node)  
                If nodeTemp IsNot Nothing Then  
                    If nodeTemp.Visible AndAlso nodeTemp.Root.Equals(Me.diagram1.Model) Then  
                        diagram1.View.SelectionList.Clear()  
                        diagram1.View.SelectionList.Add(TryCast(e.Node.Tag, Node))  
MessageBox.Show(nodeTemp.Name) 
                        diagram1.Focus()  
                    End If  
                End If  
            End If  
        End Sub  
 
Sample:  
 
Sample  
 
Regards,  
 
Naganathan K G   
 
 



AL Allen February 21, 2018 07:11 AM UTC

Dear Naganathan,

Thank you so much! It does show the message with selected node. But sometimes, the mouse click doesnt send node selection. I had to click (on the node tree of the document explorer) twice or more to get a node selected on the diagram sheet.

Am now trying a better option

Instead, how can I loop through all the nodes in the document explorer (or on the diagram sheet) so that I can write each node name to one text file? For instance, if I have five nodes in the diagram sheet, i will have a list of five node names in a text file.  When I loop, the program selects a node and sends its name to a file, then selects the second node and sends its name to the text file,, ... until the last node on the diagram sheet. I need to make sure that each nodes are selected separately and all the names are listed in the file. 

I would appreciate if you can help me on this. 

Many thanks




NG Naganathan Ganesh Babu Syncfusion Team February 22, 2018 04:01 AM UTC

Hi Allen, 
 
We are not able to reproduce the reported issue at our end. please refer to the below attached video. 
 
Video: 
 
 
Please share us more information about your requirement as such as video or screenshot for how to reproduce the reported issue at our end which will help us to analyze further and provide you a better solution. 
 
Regards, 
 
Naganathan K G 



AL Allen February 22, 2018 09:12 AM UTC

Dear Naganathan,

Thanks. Indeed, the code is fine. Maybe the mouse I use doesnt press well.

Is it possible to loop over the nodes and get parameters information (from propertyEditor) for each node? 



NG Naganathan Ganesh Babu Syncfusion Team February 23, 2018 06:29 AM UTC

Hi Allen, 
 
Is it possible to loop over the nodes and get parameters information (from propertyEditor) for each node?  
In order to achieve your requirement, we suggest you to use Diagram.Model’s “Nodes” collection property to get the node’s parameter with looping the nodes collection. 
 
[VB] 
 
Dim nodes As Nodecollection = diagram1.Model.Nodes  
 
foreach(Node node in nodes) 
  //add your logic codes here… 
 
 
For instance, if I have five nodes in the diagram sheet, i will have a list of five node names in a text file.  When I loop, the program selects a node and sends its name to a file, then selects the second node and sends its name to the text file,, ... until the last node on the diagram sheet. I need to make sure that each nodes are selected separately and all the names are listed in the file.  
We suggest you to use Diagram.EventSink’s “SelectionListChanged” event to achieve your requirement. please refer to the below code example and sample. 
 
Code example: 
 
[VB] 
 
AddHandler diagram1.EventSink.SelectionListChanged, AddressOf EventSink_SelectionListChanged 
 
            Private Sub EventSink_SelectionListChanged(ByVal evtArgs As CollectionExEventArgs) 
            If evtArgs.ChangeType = CollectionExChangeType.Insert AndAlso evtArgs.Element IsNot Nothing Then 
                Dim node As Node = TryCast(evtArgs.Element, Node) 
                Dim BasePath As String = Path.GetDirectoryName(Application.ExecutablePath) 
                'Refresh the File content 
                If File.Exists(BasePath & "\nodeinfo.txt") Then 
                    File.WriteAllText(BasePath & "\nodeinfo.txt", String.Empty) 
                End If 
                Dim writer As New StreamWriter(BasePath & "\nodeinfo.txt", True) 
                writer.WriteLine(node.Name) 
                writer.Close() 
            End If 
                        End Sub 
 
Sample: 
 
 
Video: 
 
 
 
Regards, 
 
Naganathan K G 



AL Allen February 23, 2018 08:16 AM UTC

Dear Naganathan,

Thank you so much.  Your first answer answered my second question to loop through the nodes and save node names.  Thanks a lot
In this particular sample (just to use the sample at hand),
1) I get custom property values using TryCast(Diagram1.View.SelectionList(0), className). For that, I need to declare each property values and get values with a code. But my question is: is there a way to loop through all the displayed property values in the property editor and get them once (with their names and corresponding values)? 
2) Can I gray out (disable) a property value that I don't need to use for a particular node? For instance, what if I do not want a FilePath for Car2 so that when Car2 is selected, FilePath field is grayed out (disabled I mean)?  

 









NG Naganathan Ganesh Babu Syncfusion Team February 26, 2018 09:58 AM UTC

Hi Allen, 
 
1) I get custom property values using TryCast(Diagram1.View.SelectionList(0), className). For that, I need to declare each property values and get values with a code. But my question is: is there a way to loop through all the displayed property values in the property editor and get them once (with their names and corresponding values)?  
We suggest you to use PropertyEditor.PropertyGrid.SelectedGridItem’s “GridItems” property to loop through all the dislayed property in propertyEditor. Please refer to the below code example. 
 
Code example: 
 
[VB] 
 
Dim v1 As String = propertyEditor1.PropertyGrid.SelectedGridItem.GridItems(0).Value.ToString() 
Dim v2 As String =String.Empty 
If propertyEditor1.PropertyGrid.SelectedGridItem.GridItems(1).Value IsNot Nothing Then 
v2 = propertyEditor1.PropertyGrid.SelectedGridItem.GridItems(1).Value.ToString() 
End If 
Dim v3 As String = propertyEditor1.PropertyGrid.SelectedGridItem.GridItems(2).Value.ToString() 
 
2) Can I gray out (disable) a property value that I don't need to use for a particular node? For instance, what if I do not want a FilePath for Car2 so that when Car2 is selected, FilePath field is grayed out (disabled I mean)?   
 
We suggest you to set the System.ComponentModel. ReadOnlyAttribute for particular property while defining the custom property and enable/disable to that value to gray out the property in property editor to achieve your requirement. please refer to the below code example and sample. 
 
Code example: 
 
[VB] 
 
            If diagram1.View.SelectionList.Count = 1 Then 
                                                Dim node As CustomBitmapNode = TryCast(diagram1.View.SelectionList(0), CustomBitmapNode) 
 
                                                Dim descriptor As PropertyDescriptor = TypeDescriptor.GetProperties(node.GetType())("FilePath") 
                                                Dim attrib As ReadOnlyAttribute = CType(descriptor.Attributes(GetType(ReadOnlyAttribute)), ReadOnlyAttribute) 
                                                Dim isReadOnly As FieldInfo = attrib.GetType().GetField("isReadOnly", BindingFlags.NonPublic Or BindingFlags.Instance) 
                                                Dim isvalue As Boolean = Boolean.Parse(isReadOnly.GetValue(attrib).ToString()) 
                                                If Not isvalue Then 
                                                            isReadOnly.SetValue(attrib, True) 
                                                Else 
                                                            isReadOnly.SetValue(attrib, False) 
                End If 
                propertyEditor1.PropertyGrid.Refresh() 
 
                                    End If 
 
Sample: 
 
 
Also refer to the below online link for your references. 
 
  
 
 
 
Regards, 
 
Naganathan K G 



AL Allen March 1, 2018 07:33 PM UTC

Thanks Naganathan!
The color is gray but the field is not disabled. We can still browse by clicking on the button.  I am testing another approach and will post back what I achieve (or not)


NG Naganathan Ganesh Babu Syncfusion Team March 2, 2018 11:10 AM UTC

Hi Allen,  
 
By default, the EditorAttribute (OpenFileDialog attribute) is enabled after we have disabled the PropertyGrid’s property by using System.ComponentModel. ReadOnlyAttribute. Please refer to the below link for further details which is related your queries. 
 
 
 
 
Regards, 
 
Naganathan K G 


Loader.
Up arrow icon