Example #1
0
 /// <summary>
 /// 触发节点预绑定事件
 /// </summary>
 /// <param name="e">事件参数</param>
 protected virtual void OnPreNodeDataBound(TreePreNodeEventArgs e)
 {
     EventHandler<TreePreNodeEventArgs> handler = Events[_preNodeDataBoundHandlerKey] as EventHandler<TreePreNodeEventArgs>;
     if (handler != null)
     {
         handler(this, e);
     }
 }
Example #2
0
        //private void DataBindToXml(XmlDocument xdoc)
        //{
        //    XmlNodeList nodes = xdoc.DocumentElement.ChildNodes;

        //    foreach (XmlNode node in nodes)
        //    {
        //        if (node.NodeType == XmlNodeType.Element)
        //        {
        //            TreeNode treeNode = new TreeNode();
        //            Nodes.Add(treeNode);

        //            LoadXmlNode(treeNode, node);


        //        }
        //    }
        //}

        private void DataBindToXml(TreeNode treeNode, XmlNodeList nodes)
        {
            foreach (XmlNode node in nodes)
            {
                // Only process Xml elements (ignore comments, etc)
                if (node.NodeType == XmlNodeType.Element)
                {
                    TreePreNodeEventArgs preArgs = new TreePreNodeEventArgs(node);

                    OnPreNodeDataBound(preArgs);

                    // 事件处理函数要求取消添加本节点
                    if (!preArgs.Cancelled)
                    {
                        TreeNode childNode = new TreeNode();
                        if (treeNode == null)
                        {
                            Nodes.Add(childNode);
                        }
                        else
                        {
                            treeNode.Nodes.Add(childNode);
                        }

                        childNode.ReadXmlAttributes(node.Attributes, this);

                        OnNodeDataBound(new TreeNodeEventArgs(childNode, node));


                        DataBindToXml(childNode, node.ChildNodes);
                    }
                }
            }
        }