| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 949 人关注过本帖
标题:c# treeview单击控件怎么消掉原来的内容
只看楼主 加入收藏
Donnie
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-10-19
结帖率:50%
收藏
 问题点数:0 回复次数:6 
c# treeview单击控件怎么消掉原来的内容
我在treeview控件上定义了两个radiobutton按钮一个为单位.一个为类型,现在当我单击单位后在单击类型,单位按钮的内容不刷新,而是把类型的内容叠加上去,点类型一样.要做的就是当我点单位就只出现单位的内容,点类型就只出类型的内容

最好是给代码,小弟才上,实在没有分给,对不住了,谢谢,助人为乐吗
搜索更多相关主题的帖子: 控件 单击 treeview 
2009-09-21 02:11
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
收藏
得分:0 
把工程文件传上来

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2009-09-21 08:41
Donnie
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-10-19
收藏
得分:0 
这就是
public string tn1;


        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                TreeNode tn1 = treeView1.Nodes.Add("档案管理系统");
                string SQLstr = "SELECT DISTINCT ZZLBID,ZZLBName from ZZLBTable";// where ZZLBName = 1 ";//and sn in(" + all.Substring(0, all.Length - 1).ToString() + ")";
                SqlDataAdapter objAdapterNode = new SqlDataAdapter(SQLstr, My_con);
                DataSet My_DataSet = new DataSet();
                My_DataSet.Clear();
                objAdapterNode.Fill(My_DataSet, "temp");
                DataTable dt = My_DataSet.Tables["temp"];
                tn1.Nodes.Clear();

                //建立根节点,遍历。

                foreach (DataRow dr in dt.Rows)
                {
                    TreeNode Root = new TreeNode();
                    Root.Text = dr["ZZLBName"].ToString();
                    tn1.Nodes.Add(Root);
                    //TreeView1.Nodes.add(Root);//建立根节点


                    string str = "SELECT UnitID,ZZClass from ComeFile_Base ";//where UnitID = " + dr["ZZLBID"].ToString() + "' and ComeFile_Base in (" + ZZLBName.Substring(0, ZZLBName.Length - 1).ToString() + ")" + "order by ZZLBID,UnitID";
                    SqlDataAdapter objAdapter = new SqlDataAdapter(str, My_con);
                    DataSet dsNode = new DataSet();
                    dsNode.Clear();
                    objAdapter.Fill(dsNode, "tempNode");
                    DataTable dtNode = dsNode.Tables["tempNode"];

                    //建立子节点,遍历。

                    foreach (DataRow drNode in dtNode.Rows)
                    {
                        TreeNode Node = new TreeNode();
                        Node.Text = drNode["ZZClass"].ToString();
                        //Node.Target = "RightFrame";

                        string Path = drNode["UnitID"].ToString();
                        //int menusn = Convert.ToInt32(drNode["ZZClass"].ToString());
                        Node.Name = "Transfer.aspx" + "?ZZClass=" + Path;

                        Root.Nodes.Add(Node);//建立子节点
                    }
                }
            }
            catch (Exception edf)
            {
                MessageBox.Show(" 错误!('您没有可操作的菜单项!'); " + edf.Message);
            }


        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            
            try
            {
                TreeNode tn1 = treeView1.Nodes.Add("档案管理系统");
                string SQLstr = "SELECT DISTINCT ZZLBID,ZZLBName from ZZLBTable";// where ZZLBName = 1 ";//and sn in(" + all.Substring(0, all.Length - 1).ToString() + ")";
                SqlDataAdapter objAdapterNode = new SqlDataAdapter(SQLstr, My_con);
                DataSet My_DataSet = new DataSet();
                My_DataSet.Clear();
                objAdapterNode.Fill(My_DataSet, "temp");
                DataTable dt = My_DataSet.Tables["temp"];
                tn1.Nodes.Clear();

                //建立根节点,遍历。

                foreach (DataRow dr in dt.Rows)
                {
                    TreeNode Root = new TreeNode();
                    Root.Text = dr["ZZLBName"].ToString();
                    tn1.Nodes.Add(Root);
                    //TreeView1.Nodes.add(Root);//建立根节点


                    string str = "SELECT UnitID,UnitName from ComeFile_Base ";//where UnitID = " + dr["ZZLBID"].ToString() + "' and ComeFile_Base in (" + ZZLBName.Substring(0, ZZLBName.Length - 1).ToString() + ")" + "order by ZZLBID,UnitID";
                    SqlDataAdapter objAdapter = new SqlDataAdapter(str, My_con);
                    DataSet dsNode = new DataSet();
                    dsNode.Clear();
                    objAdapter.Fill(dsNode, "tempNode");
                    DataTable dtNode = dsNode.Tables["tempNode"];

                    //建立子节点,遍历。

                    foreach (DataRow drNode in dtNode.Rows)
                    {
                        TreeNode Node = new TreeNode();
                        Node.Text = drNode["UnitName"].ToString();
                        //Node.Target = "mainbottom";

                        string Path = drNode["UnitID"].ToString();
                        //int menusn = Convert.ToInt32(drNode["ZZClass"].ToString());
                        Node.Name = "Transfer.aspx" + "?UnitName=" + Path;

                        Root.Nodes.Add(Node);//建立子节点



                    }
                }
            }
               
            catch (Exception edf)
            {
                MessageBox.Show(" 错误!('您没有可操作的菜单项!'); " + edf.Message);
            }

        }
2009-09-21 09:42
Mo诫
Rank: 4
等 级:业余侠客
帖 子:80
专家分:223
注 册:2009-7-29
收藏
得分:0 
你这样的写法如果数据很多那会加载N久的!最好开始只加载一到2个结点,当点击一个结点时再加载它的子节点
至于你的问题:
e.Node.Nodes.Clear();

e.Node就是你的结点相当于Root.Nodes.Add(Node);//建立子节点 中的Root
2009-09-21 17:37
Mo诫
Rank: 4
等 级:业余侠客
帖 子:80
专家分:223
注 册:2009-7-29
收藏
得分:0 
                TreeNode tn1 = treeView1.Nodes.Add("档案管理系统");
                string SQLstr = "SELECT DISTINCT ZZLBID,ZZLBName from ZZLBTable";// where ZZLBName = 1 ";//and sn in(" + all.Substring(0, all.Length - 1).ToString() + ")";
                SqlDataAdapter objAdapterNode = new SqlDataAdapter(SQLstr, My_con);
                DataSet My_DataSet = new DataSet();
                My_DataSet.Clear();

不知道你发现没有。。。你每个结点都会去用到这样的代码!你完全可以写到类调用这个方法嘛,这样程序和可读性会高很多的!
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
 
namespace FileManageSystem
{
    class BasesOperate
    {
        //
        //F_str_sqlcn 连接数据库字符串
        //F_str_str要执行的SQL语句
        //F_str_table数据集表
        //F_trd_trvNode选中的树型节点
        //
 
        #region & SqlConnection
        public SqlConnection GetCon()
        {
            string F_str_sqlcn="data source=10.10.2.118\\SQLEXPRESS;Initial Catalog=DocumentManage;User ID=document;Password=123 \r\n";
            SqlConnection sqlcn = new SqlConnection(F_str_sqlcn);
            return sqlcn;
        }
        #endregion
 
        #region & DataSet
        public DataSet Getds(string F_str_str,string F_str_table)
        {
            SqlConnection sqlcn = this.GetCon();
            sqlcn.Open();
            SqlDataAdapter myda=new SqlDataAdapter (F_str_str,sqlcn);
            DataSet myds = new DataSet();
            myda.Fill(myds,F_str_table);
            return myds;
        }
        #endregion

        #region & Level Of Node 判断当前节点级别 可以用这个实现选择一个节点再去加载它的子节点
        public int LevelOfNode(TreeNode F_trd_trvNode)
        {
            int x = 1;
            if (F_trd_trvNode.Parent != null)
            {
                return LevelOfNode(F_trd_trvNode.Parent) + 1;
            }
            else
                return x;
        }  
        #endregion

    }
}
2009-09-21 17:44
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:0 
Mo诫

你真棒!哈哈...
最近忙什么呢?
2009-09-22 00:38
Donnie
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-10-19
收藏
得分:0 
大侠们,那么还是不行啊
2009-09-22 13:57
快速回复:c# treeview单击控件怎么消掉原来的内容
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015521 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved