在combobox中嵌入treeview

原创 2011年01月11日 17:11:00

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace ZhongBaoTech.LS.LSUI
{
    /// <summary>
    /// 嵌套了combobox的treeview
    /// 郑雯柯2010-12-29
    /// </summary>
    public class ComboBoxTreeView : ComboBox
    {
        private const int WM_LBUTTONDOWN = 0x201, WM_LBUTTONDBLCLK = 0x203;
        ToolStripControlHost treeViewHost;
        ToolStripDropDown dropDown;

        public ComboBoxTreeView(TreeView treeView)
        {
            treeView.AfterSelect += new TreeViewEventHandler(treeView_AfterSelect);
            treeView.BorderStyle = BorderStyle.None;
            treeView.HideSelection = false;
            treeViewHost = new ToolStripControlHost(treeView);
            dropDown = new ToolStripDropDown();
            dropDown.Width = this.Width;
            dropDown.Items.Add(treeViewHost);
            this.KeyPress += new KeyPressEventHandler(MyKeyPress);
        }

        public void treeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.Items.Clear();
            this.Items.Add(TreeView.SelectedNode.Text);
            this.Text = TreeView.SelectedNode.Text;
            this.Name = TreeView.SelectedNode.Name;
            this.Tag = TreeView.SelectedNode.Tag;
            //this.Focus();
            dropDown.Close();
        }

        public void SetCurSelected(TreeNode node)
        {
            this.TreeView.SelectedNode = node;
            this.Items.Clear();
            this.Items.Add(TreeView.SelectedNode.Text);
            this.SelectedIndex = 0;
            this.Name = TreeView.SelectedNode.Name;
            this.Tag = TreeView.SelectedNode.Tag;
        }

        public TreeView TreeView
        {
            get { return treeViewHost.Control as TreeView; }
        }

        private void MyKeyPress(object sender, KeyPressEventArgs e)
        {
            e.KeyChar = (char)0;
        }

        private void ShowDropDown()
        {
            if (dropDown != null)
            {
                treeViewHost.Size = new Size(DropDownWidth - 2, DropDownHeight);
               


                dropDown.Show(this, 0, this.Height);
            }
        }

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_LBUTTONDBLCLK || m.Msg == WM_LBUTTONDOWN)
            {
                ShowDropDown();
                return;
            }
            base.WndProc(ref m);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (dropDown != null)
                {
                    dropDown.Dispose();
                    dropDown = null;
                }
            }
            base.Dispose(disposing);
        }
    }
}

 

调用:

            ComboBoxTreeView comboTrv;  //嵌套了treeview的combobox

            TreeView trv = new TreeView();
            ClsTreeView.InitMateCodeStruList(trv, TC_MateCodeStruList.List(LSUserInfo.Pid), true);
            trv.Nodes[0].Expand();
            comboTrv = new ComboBoxTreeView(trv);
            comboTrv.SelectedIndexChanged += comboBox6_SelectedIndexChanged;
            comboTrv.Left = 92;
            comboTrv.Top = 8;
            comboTrv.Width = 221;
            this.panel2.Controls.Add(comboTrv);

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

下拉列表框弹出树(ComboBoxTreeView)

using System.Data;using System.Text;using System.Windows.Forms;namespace WinApp{    public class Com...

VS2008下水晶报表之简单示例

1、先新建一个Web项目2、在刚刚新建的项目下,为项目添加新项,如: CrystalReport1.rpt     在弹出的对话框,选择作为空白报表。用向导当然更方便。3、在工具箱选择 Text Ob...

WPF 制作带TreeView的ComBox

1、xaml代码部分

ComboBox+TreeView+自动补全

  • 2011-10-31 11:38
  • 98KB
  • 下载

自定义控件---动态无限级生成 级联comboBox 和 treeView

开始 -〉新建 -〉新建项目 -〉“Windows窗体控件库” 名称栏 里 改为: myControl1 贴上下面的代码: using System; using System.Collectio...

MFC——LIstCtrl中嵌入Edit和Combobox控件

在MFC中经常会使用到ListCtrl控件,并且在控件中可以对单元格进行Edit的编辑或者ComboBox的编辑。实现ListCtrl中用edit和combobox编辑并数据同步,下面就是我用到的这个...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)