|
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:
|
|
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.
|