Quickstarts.HistoricalEvents.Client.SelectTypeDlg.ShowDialog C# (CSharp) Method

ShowDialog() public method

Displays the available areas in a tree view.
public ShowDialog ( Session session, NodeId rootId, string caption ) : TypeDeclaration
session Session The session.
rootId NodeId
caption string
return TypeDeclaration
        public TypeDeclaration ShowDialog(Session session, NodeId rootId, string caption)
        {
            m_session = session;

            // set the caption.
            if (!String.IsNullOrEmpty(caption))
            {
                this.Text = caption;
            }

            // set default root.
            if (NodeId.IsNull(rootId))
            {
                rootId = Opc.Ua.ObjectTypeIds.BaseEventType;
            }

            m_rootId = rootId;

            // display root.
            TreeNode root = new TreeNode(session.NodeCache.GetDisplayText(rootId));
            root.Nodes.Add(new TreeNode());
            BrowseTV.Nodes.Add(root);
            root.Expand();
            BrowseTV.SelectedNode = root;

            // display the dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return null;
            }

            // ensure selection is valid.
            if (BrowseTV.SelectedNode == null)
            {
                return null;
            }

            // get the currently selected event.
            NodeId typeId = m_rootId;
            ReferenceDescription reference = BrowseTV.SelectedNode.Tag as ReferenceDescription;

            if (reference != null)
            {
                typeId = (NodeId)reference.NodeId;
            }

            TypeDeclaration declaration = new TypeDeclaration();
            declaration.NodeId = typeId;
            declaration.Declarations = new List<InstanceDeclaration>();

            // update selected fields.
            for (int ii = 0; ii < DeclarationsLV.Items.Count; ii++)
            {
                InstanceDeclaration instance = DeclarationsLV.Items[ii].Tag as InstanceDeclaration;

                if (instance != null)
                {
                    declaration.Declarations.Add(instance);
                }
            }

            // return the result.
            return declaration;
        }
        #endregion