private List<DataRow> list = new List<DataRow>();

        Boolean afterCheck = true;

        /// <summary>
        /// 当已选中或取消树复选框时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
        {
            if (e.Action == TreeViewAction.ByMouse || e.Action == TreeViewAction.ByKeyboard)
            {
                if (afterCheck)
                {
                    afterCheck = false;
                    if (e.Node == null) return;
                    TreeNode treeNode = e.Node;
                    if (treeNode.Checked)
                    {
                        TreeNode treeNodeTemp = treeNode;
                        #region
                        if (treeNodeTemp.Nodes.Count != 0)
                        {
                            AddMjNodeList(treeNodeTemp, true);
                        }
                        else
                        {
                            if (treeNodeTemp.Tag !=null)
                            list.Add((DataRow)treeNodeTemp.Tag);
                        }
                        #endregion
                        while (treeNodeTemp.Parent != null)
                        {
                            treeNodeTemp = treeNodeTemp.Parent;
                            if (!treeNodeTemp.Checked)
                            {
                                treeNodeTemp.Checked = treeNode.Checked;
                            }
                        }
                    }
                    /// 添加人员: 阿朝
                    /// 添加时间: 20090724
                    else
                    {
                        int state = 0;
                        TreeNode treeNodeTemp = treeNode;
                        #region
                        if (treeNodeTemp.Nodes.Count != 0)
                        {
                            AddMjNodeList(treeNodeTemp, false);
                        }
                        else
                        {
                            if (treeNodeTemp.Tag!=null)
                            DeleteList(list, treeNodeTemp);
                        }
                        #endregion
                        while (treeNodeTemp.Parent != null)
                        {
                            if (CheckPrevOrNextNode(treeNodeTemp))
                            {
                                state = 1;
                            }
                            treeNodeTemp = treeNodeTemp.Parent;
                            treeNodeTemp.Checked = Convert.ToBoolean(state);
                        }
                    }
                    treeViewNodesCheck(treeNode, treeNode.Checked);

                    afterCheck = true;
                }
            }
        }

         /// <summary>
        /// 选中节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            //if (e.Action == TreeViewAction.ByMouse || e.Action == TreeViewAction.ByKeyboard)
            //{
            //    if (afterCheck)
            //    {
            //        afterCheck = false;
            //        //if (!btnSave.Enabled) btnSave.Enabled = true;
            //        //if (!btnCancel.Enabled) btnCancel.Enabled = true;
            //        if (e.Node == null) return;
            //        TreeNode treeNode = e.Node;
            //        if (treeNode.Checked)
            //        {
            //            TreeNode treeNodeTemp = treeNode;
            //            while (treeNodeTemp.Parent != null)
            //            {
            //                treeNodeTemp = treeNodeTemp.Parent;
            //                if (!treeNodeTemp.Checked)
            //                {
            //                    treeNodeTemp.Checked = treeNode.Checked;
            //                }
            //            }
            //        }
            //        /// 添加人员:  阿朝
            //        /// 添加时间: 20090724
            //        else
            //        {
            //            int state = 0;
            //            TreeNode treeNodeTemp = treeNode;

            //            while (treeNodeTemp.Parent != null)
            //            {
            //                if (CheckPrevOrNextNode(treeNodeTemp))
            //                {
            //                    state = 1;
            //                }
            //                treeNodeTemp = treeNodeTemp.Parent;
            //                treeNodeTemp.Checked = Convert.ToBoolean(state);

            //            }
            //        }
            //        treeViewNodesCheck(treeNode, treeNode.Checked);

            //        afterCheck = true;
            //    }
            //}
        }

        #region 树方法

        private void treeViewNodesCheck(TreeNode treeNode, Boolean check)
        {
            foreach (TreeNode treeNodeChild in treeNode.Nodes)
            {
                treeNodeChild.Checked = check;
                treeViewNodesCheck(treeNodeChild, check);
            }
        }

        /// <summary>
        /// 添加人员: 阿朝
        /// 添加时间: 20090724
        /// </summary>
        /// <param name="node"></param>
        private bool CheckPrevOrNextNode(TreeNode node)
        {
            bool falg = false;

            /// 检查同级的前个节点是否选中
            while (node.PrevNode != null)
            {
                if (node.PrevNode.Checked)
                {
                    falg = true;
                    break;
                }
                else
                {
                    node = node.PrevNode;
                }
            }
            /// 检查同级节点的后一个节点是否选中
            while (node.NextNode != null)
            {
                if (node.NextNode.Checked)
                {
                    falg = true;
                    break;
                }
                else
                {
                    node = node.NextNode;
                }
            }
            return falg;
        }

        #endregion

 

 

  private void DeleteList(List<DataRow> listRow,TreeNode treeNodeNew)
   {
            List<DataRow> listRowCopy = new List<DataRow>();
            foreach (DataRow drownew in listRow)
            {
                listRowCopy.Add(drownew);
            }
            foreach (DataRow drow in listRowCopy)
            {
                DataRow drowNew = (DataRow)treeNodeNew.Tag;
                if (drowNew["sdx"].ToString() == drow["sdx"].ToString())
                {
                    list.Remove(drowNew);
                }
            }
        }

 

        private void AddMjNodeList(TreeNode treeNodeNew,bool falg)
        {

            if (treeNodeNew.Nodes.Count == 0)
            {
                if (falg)
                {
                    list.Add((DataRow)treeNodeNew.Tag);
                }
                else
                {
                    DeleteList(list,treeNodeNew);
                }
            }
            else
            {
                for (int i = 0; i < treeNodeNew.Nodes.Count; i++)
                {
                    AddMjNodeList(treeNodeNew.Nodes[i], falg);
                }
            }
              
                //TreeNode treeNodeNext = treeNodeNew.NextNode;
                //if (treeNodeNext != null)
                //{
                //    AddMjNodeList(treeNodeNext, falg);
                //}
                //TreeNode treeNodeprv = treeNodeNew.PrevNode;
                //if (treeNodeprv != null)
                //{
                //    AddMjNodeList(treeNodeprv, falg);
                //}
        
            //while (treeNodeNew.NextNode != null)
            //{
            //    //TreeNode treeNodeNext = treeNodeNew.NextNode;
            //    //if (treeNodeNext != null)
            //    //{
            //    AddMjNodeList(treeNodeNew.NextNode, falg);
            //    //}
            //}
            //while (treeNodeNew.PrevNode != null)
            //{
            //    //TreeNode treeNodeprv = treeNodeNew.PrevNode;
            //    //if (treeNodeprv != null)
            //    //{
            //    AddMjNodeList(treeNodeNew.PrevNode, falg);
            //    //}
            //}
    
        }

阅读更多
文章标签: null object list
个人分类:
上一篇Oreacl Rownum 的使用
下一篇EXCEL Export
想对作者说点什么? 我来说一句

B树,B树,B+树,B树简介

2010年09月09日 309KB 下载

JS树,树组件,javascript树

2011年07月12日 42KB 下载

js动态树菜单(只供参考)

2009年11月04日 4KB 下载

树及异步树

2011年09月14日 8.98MB 下载

哈弗曼树的代码

2018年04月17日 10.69MB 下载

菜单树JQUERY

2011年10月20日 2.44MB 下载

没有更多推荐了,返回首页

关闭
关闭