Since you want the information to be display, I assume you want to (or perhaps have already) implement AFTreeView_AfterSelect event. This gets triggered when user select a node (AFElement or AFAttribute) in the AFTreeView. You can get the selected node from the event arguments (TreeViewEventArgs) and handle the different cases appropriately, like the following:
Private Sub AfTreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs)
Dim _SelectedNode As AFTreeNode = DirectCast(e.Node, AFTreeNode)
If _SelectedNode.AFObject.GetType().Name = "AFAttribute" Then
' if selected node is an AFAttribute
Dim _AFAttribute As AFAttribute = DirectCast(_SelectedNode.AFObject, AFAttribute)
' use AFViewControl to show the property of the attribute
AfViewControl1.AFSetObject(_AFAttribute, Nothing, Nothing, Nothing)
ElseIf _SelectedNode.AFObject.GetType().Name = "AFElement" Then
Dim _AFElement As AFElement = DirectCast(_SelectedNode.AFObject, AFElement)
' use AFViewControl to show the property of the element
AfViewControl1.AFSetObject(_AFElement, Nothing, Nothing, Nothing)
I am using AFViewControl to display the AFAttribute or AFElement information here, one of the AF UI controls that can be used easily to display information of AFObjects.
Thanks for the code. Quick question; will the AFViewControl allow me to set the value of a tag if it's ReadOnly=False?
Yes, it is allowed. Another consideration on top of "ReadOnly=False" is that the user should have sufficient rights to do that as well. if user does not have the sufficient rights to write/make changes to AF, the fields would be greyed out.
All these must be true before you can write a value to a PI Point from the ViewControl:
1) PI Point Data Reference must be configure so "ReadOnly=False"
2) User must have "Write Data" security privileges in the element
3) User must have "Write" privilege for PI Point Data Security
4) The ViewControl.ReadOnly flag must be set to false
Quick question about point 3. For point 2, I just have to grab my AFSecurity for the element and call the CanWriteData object to check to see if the current user can "write data". Is there a similar object in the AFSecurity for this or do I have to do it through the PI SDK?
The "Write" privilege for PI Point Data Security that Chris mentioned is part of the PI Point configuration so you will have to use PI SDK to access this information. Specifically you will have to access the "DataSecurity" attribute to find what privilege PIusers or PIidentities have to the PI Point.
' get pipoint from AF attribute
Dim _PIPoint As PISDK.PIPoint = _AFAttribute.RawPIPoint
If Not _PIPoint Is Nothing Then
If you have a version of PI server older than 3.4.380 then the relavant attribute should be "DataAccess", "DataOwner" and "DataGroup" instead. You probably have to have an idea what PIuser/PIidentity that the user will be mapped/trusted as well. These will be more related to security configuration on the PI server.
If user have sufficient privileges for point 1, 2 and 4 that Chris pointed out but not point 3, the user should see a error dialog box that indicate that he/she do not have write privilege to the PI Point.