资源简介

C# winform TreeView树形菜单控件DEMO附配套数据库文件 【VS2008】+【SQL Sever 2005】 温馨提示:下载完了回复一下就能把分数再赚回去哟~

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace TreeView
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            ShowNodes();
           
        }

        //搜索结点
        private void ShowNodes()
        {
            SqlConnection con = new SqlConnection(“Data Source=localhost;Initial Catalog=ll;Integrated Security=True“);
            con.Open();
            string sql = “select * from Menu“;
            SqlDataAdapter sda = new SqlDataAdapter(sql con);
            DataSet ds = new DataSet();
            sda.Fill(ds “Menu“);
            DataTable dt = ds.Tables[“Menu“];
            string rank1 = “rank=0“;
            DataRow[] rows = dt.Select(rank1);

            foreach (DataRow tdr1 in rows)
            {//添加根结点

                //this.treeView1.Nodes.Add(dr[“name“].ToString());
                TreeNode tn1 = new TreeNode();
                tn1.Tag = tdr1[“ID“];
                tn1.Text = tdr1[“name“].ToString();
                this.treeView1.Nodes.Add(tn1);

                string rank2 =“rank=1 and parentID=“ + Convert.ToInt32(tdr1[“ID“].ToString());
                DataRow[] dr2 = dt.Select(rank2);
                foreach (DataRow tdr2 in dr2)
                { //添加2级结点


                    TreeNode tn2 = new TreeNode();
                    tn2.Tag = tdr2[“ID“];
                    tn2.Text = tdr2[“name“].ToString();
                    tn1.Nodes.Add(tn2);

                    string rank3 =“rank=2 and parentID=“ + Convert.ToInt32(tdr2[“ID“].ToString());
                    DataRow[] dr3 = dt.Select(rank3);
                    foreach (DataRow tdr3 in dr3)
                    {//添加3级结点


                        TreeNode tn3 = new TreeNode();
                        tn3.Tag = tdr3[“ID“];
                        tn3.Text = tdr3[“name“].ToString();
                        tn2.Nodes.Add(tn3);
                    }
                }



            }

        }



        private void treeView1_Click(object sender EventArgs e)
        {
          
        }
        private void add(object sender EventArgs e)
        {


        }

        private void contextMenu1_Popup(object sender EventArgs e)
        {
            contextMenu1.MenuItems.Clear();
            contextMenu1.MenuItems.Add(“增加“ new EventHandler(this.add));
        }

        private void treeView1_AfterSelect(object sender TreeViewEventArgs e)
        {
            this.treeView1.ContextMenu = this.contextMenu1;
        }

        private void menuItem1_Click(object sender EventArgs e)
        {
            //删除
            SqlConnection con = new SqlConnection(“Data

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5494  2008-01-18 10:20  TreeView\Backup\TreeView\Form1.cs

     文件       4251  2008-01-17 18:28  TreeView\Backup\TreeView\Form1.Designer.cs

     文件       6014  2008-01-17 18:28  TreeView\Backup\TreeView\Form1.resx

     文件        467  2008-01-17 12:43  TreeView\Backup\TreeView\Program.cs

     文件       1176  2008-01-17 10:51  TreeView\Backup\TreeView\Properties\AssemblyInfo.cs

     文件       2839  2008-01-17 12:43  TreeView\Backup\TreeView\Properties\Resources.Designer.cs

     文件       5612  2008-01-17 10:51  TreeView\Backup\TreeView\Properties\Resources.resx

     文件       1105  2008-01-17 12:43  TreeView\Backup\TreeView\Properties\Settings.Designer.cs

     文件        249  2008-01-17 10:51  TreeView\Backup\TreeView\Properties\Settings.settings

     文件       3260  2008-01-17 12:43  TreeView\Backup\TreeView\TreeView.csproj

     文件        913  2008-01-17 10:51  TreeView\Backup\TreeView.sln

    ..A..H.     12800  2008-01-17 21:26  TreeView\Backup\TreeView.suo

     文件    1638400  2010-01-08 22:51  TreeView\Data\tv_Data.MDF

     文件    3538944  2010-01-08 22:51  TreeView\Data\tv_Log.LDF

     文件      12288  2010-01-05 17:05  TreeView\TreeView\bin\Debug\TreeView.exe

     文件      30208  2010-01-05 17:05  TreeView\TreeView\bin\Debug\TreeView.pdb

     文件      14328  2010-01-08 21:05  TreeView\TreeView\bin\Debug\TreeView.vshost.exe

     文件        490  2007-07-21 02:33  TreeView\TreeView\bin\Debug\TreeView.vshost.exe.manifest

     文件       5488  2010-01-05 17:05  TreeView\TreeView\Form1.cs

     文件       4251  2008-01-17 18:28  TreeView\TreeView\Form1.Designer.cs

     文件       6014  2008-01-17 18:28  TreeView\TreeView\Form1.resx

     文件       4608  2010-01-05 14:19  TreeView\TreeView\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        803  2010-01-08 21:05  TreeView\TreeView\obj\Debug\TreeView.csproj.FileListAbsolute.txt

     文件        847  2010-01-05 14:19  TreeView\TreeView\obj\Debug\TreeView.csproj.GenerateResource.Cache

     文件      12288  2010-01-05 17:05  TreeView\TreeView\obj\Debug\TreeView.exe

     文件        180  2010-01-05 14:19  TreeView\TreeView\obj\Debug\TreeView.Form1.resources

     文件      30208  2010-01-05 17:05  TreeView\TreeView\obj\Debug\TreeView.pdb

     文件        180  2010-01-05 14:19  TreeView\TreeView\obj\Debug\TreeView.Properties.Resources.resources

     文件        275  2008-01-18 13:17  TreeView\TreeView\obj\TreeView.csproj.FileList.txt

     文件        467  2008-01-17 12:43  TreeView\TreeView\Program.cs

............此处省略29个文件信息

评论

共有 条评论