/// <summary> /// Browses for children of the element at the current node. /// </summary> private void Browse(TreeNode node) { try { // get the server for the current node. TsCDaServer server = FindServer(node); // get the current element to use for a browse. TsCDaBrowseElement parent = null; OpcItem itemID = null; if (node.Tag != null && node.Tag.GetType() == typeof(TsCDaBrowseElement)) { parent = (TsCDaBrowseElement)node.Tag; itemID = new OpcItem(parent.ItemPath, parent.ItemName); } // clear the node children. node.Nodes.Clear(); // add properties if (parent != null && parent.Properties != null) { foreach (TsCDaItemProperty property in parent.Properties) { AddItemProperty(node, property); } } // begin a browse. OpcClientSdk.Da.TsCDaBrowsePosition position = null; TsCDaBrowseElement[] elements = server.Browse(itemID, m_filters, out position); // add children. if (elements != null) { foreach (TsCDaBrowseElement element in elements) { AddBrowseElement(node, element); } node.Expand(); } // loop until all elements have been fetched. while (position != null) { DialogResult result = MessageBox.Show( "More items meeting search criteria exist. Continue browse?", "Browse Items", MessageBoxButtons.YesNo); if (result == DialogResult.No) { break; } // fetch next batch of elements,. elements = server.BrowseNext(ref position); // add children. if (elements != null) { foreach (TsCDaBrowseElement element in elements) { AddBrowseElement(node, element); } node.Expand(); } } // send notification that property list changed. if (ElementSelected != null) { if (node.Tag.GetType() == typeof(TsCDaBrowseElement)) { ElementSelected((TsCDaBrowseElement)node.Tag); } else { ElementSelected(null); } } } catch (Exception e) { MessageBox.Show(e.Message); } }