学无止境的专栏

Live And Learn

TreeView的使用

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Data;
namespace Charge
{
    public class TreeFunction
    {
        public void TreeRoot(ref TreeView myT, Form myForm)
        {

            foreach (MenuItem myMI in myForm.Menu.MenuItems)
            {
                TreeNode myTreeN = new TreeNode();
                myTreeN.Text = myMI.Text;
                TreeNod(myMI, myTreeN, false);
                myT.Nodes.Add(myTreeN);
            }
            myT.ShowRootLines = true;
            myT.SelectedNode = myT.Nodes[0];
            myT.Focus();
        }
        public TreeNode TreeNod(System.Windows.Forms.MenuItem m, TreeNode asTN, bool asbl)
        {
            TreeNode TreeN1 = new TreeNode();
            //if (asbl && m.Text!=System.Convert.ToString('-'))
            if (asbl)
            {
                TreeN1.Text = m.Text;
                asTN.Nodes.Add(TreeN1);
            }
            else
            {
                TreeN1 = asTN;
            }
            foreach (System.Windows.Forms.MenuItem subm in m.MenuItems)
            {
                TreeNod(subm, TreeN1, true);
            }
            return TreeN1;
        }
        public void TreeSetRightByUserGroup(string UserGroupbm, TreeNodeCollection myTree, wglpforever  myConM)
        {
            DataSet myDS;
            foreach (TreeNode tn in myTree)
            {
                string lsSql = "select * from drv_bksf.drv_usergroupmenu where usergroupbm='" + UserGroupbm + "' and usergroupmenu='" + tn.Text + "'";
                myDS = myConM.Data_Fill(lsSql, "drv_fei_usergroupmenu");
                if (myDS == null)
                {
                    return;
                }
                if (myDS.Tables[0].Rows.Count == 1)
                {
                    tn.Checked = true;

                }
                else
                {
                    tn.Checked = false;
                }
                myDS.Clear();
                if (tn.Nodes.Count != 0)
                    TreeSetRightByUserGroup(UserGroupbm, tn.Nodes,myConM);
            }
        }
        //选择子节点
        public void TreeSelectRight(TreeNodeCollection myTree, bool myIndex)
        {
            foreach (TreeNode tn in myTree)
            {
                tn.Checked = myIndex;
            }
        }
        //选择父节点
        public void TreeSelectParent(TreeNode Tn, bool lsCheck)
        {
            if (Tn.Parent == null) return;
            switch (lsCheck)
            {
                case true:
                    Tn.Parent.Checked = true;
                    break;
                case false:
                    Tn.Parent.Checked = false;
                    break;
                default:
                    break;
            }
        }
        public int TreeSaveRight(string UserGroupbm, TreeNodeCollection myTree, wglpforever myConM)
        {

            foreach (TreeNode tn in myTree)
            {
                if (tn.Checked == true)
                {
                    string lsSql = "insert into  drv_bksf.drv_usergroupmenu(usergroupbm,usergroupmenu) values('" + UserGroupbm + "','" + tn.Text + "')";
                    try
                    {
                        myConM.IUDBySql(lsSql);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString(), "error");
                        return 0;
                    }
                }
                if (tn.Nodes.Count != 0)
                    TreeSaveRight(UserGroupbm, tn.Nodes, myConM);
            }
            return 1;
        }
    }
}
  

阅读更多
个人分类: .NET学习
上一篇大型Web2.0站点构建技术初探
下一篇ASP.Net2.0页面无刷新境界体验
想对作者说点什么? 我来说一句

TreeView使用集锦

2009年06月25日 4KB 下载

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

关闭
关闭