内容显示页
 
类别:.Net + C# | 浏览(3913) | 2009-5-14 22:49:26

ComboBoxTree
平时常用无限级分类,只是这个无限级树,每次都得拖ComboBox,设置,拖TreeView,再设置,代码里也得整来整去,很是麻烦,也很是不爽,所以改造下。

不过我的水平想组合这两个东西,可太有难度了,所以还是上网上找到,在CodeProject上找到一个评价还不错的,拿下来修改,改造了两天,终于可以很方便的使用了。

不过还是我的水平问题,这个控件使用的东西很多理解不了,所以感觉改的不是很好,只能说能很方便的使用。

调用方法:

填充:comboBoxTree1.Fill(DataTable dt, object ParentID)
 

        /// <summary>
        /// 填充Tree
        /// </summary>
        /// <param name="ParentID">父级编号</param>
        /// <param name="dt">格式,三列,Id,Name,ParentId,只要顺序一样就可以了</param>
        public void Fill(DataTable dt, object ParentID)

设置值:SelectedByValue(object value, object text)

        /// <summary>
        /// 根据值来查找
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="text">Text可以随便写,当然,最好是什么就写什么</param>
        public void SelectedByValue(object value, object text)

取值:Text,Value,FullPath

comboBoxTree1.Value
comboBoxTree1.Text
comboBoxTree1.FullPath
 

 

主要代码太多,这里只发他的调用方法吧:

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

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

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBoxTree1.Fill(GetDataTable(), "0");
        }

        private void btnGet_Click(object sender, EventArgs e)
        {
            MessageBox.Show(
                "Value:"+comboBoxTree1.Value+
                "\nText:"+comboBoxTree1.Text+
                "\nFullPath:"+comboBoxTree1.FullPath
                
                );
        }

        private void btnSet_Click(object sender, EventArgs e)
        {
            //comboBoxTree1.SelectedByValue(3, "Name333");
            comboBoxTree1.SelectedByValue(3, "Name3");
        }



        private DataTable GetDataTable()
        {

            string[,] array3D = { 
                                { "1", "ComboBoxTree1", "0"}, 
                                { "2", "ComboBoxTree2", "1"}, 
                                { "3", "ComboBoxTree3", "1"}, 
                                { "4", "ComboBoxTree4", "2"}, 
                                { "5", "ComboBoxTree5", "2"}, 
                                { "6", "ComboBoxTree6", "5"}, 
                                };
            return ArrayToDataTable.ArrayToDataTable.Convert(array3D);
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("Iexplore.exe", "http://www.yongfa365.com/");
        }

    }
}

演示文件及相关源码下载地址:ComboBoxTree.rar

 主要代码来源与:http://www.codeproject.com/KB/miscctrl/CSDropDownPanel.aspx


引用:
[.net自定义控件]ComboBox与TreeView组合控件 ComboBoxTree
http://www.yongfa365.com/item/ComboBoxTree.html
 
 
相关链接
 
网友评论:
1 fan - 2010-4-6 11:14:30
我想问问你 类似于combobox 的selectindexchange事件好像没有
我用那个valuechange 事件好向捕捉不到,怎么回事
 
2 流月恒行 - 2012-1-28 22:55:20
这个东西怎么用啊?我用的是vs2008,菜鸟,不知道把哪段代码加进去为己所用,急用啊
 
姓名: 记住我
网址:
邮箱:
内容:
验证码:  验证码图片 看不清? 换张图试试
 
     
 
 
文章分类
 
 
.Net + C#(74)
 
 
ASP+VBS(161)
 
 
 
Linux(10)
 
 
 
web 2.0(26)
 
 
 
 
 
心程(68)
 
生活(97)
 
 
     

Power by :柳永法(yongfa365)'Blog  | 京ICP备07011491号  QQ:64049027  E-mail:64049027@qq.com Weibo

申请友情链接 要求:跟本站主题相类似正规网站,双方交换为首页位置

转载请注明来源,以便后人及时得到最新、修正、加强版!!!