在winform中怎样把整个treeview加入combobox? 在winform中怎样把整个treeview加入combobox?winform没有dropdownlist 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 自己做个usercontrol吧,放一个combox下面放treeview,点击下拉时,当然可以不用combox,用一个edit+button模仿,点击button时,显示treeview http://www.codeproject.com/Articles/17592/DropDownPanelhttp://www.codeproject.com/Articles/3994/Custom-ComboBoxes-with-Advanced-Drop-down-Features 用一个edit+button模仿,点击button时,显示treeview,但是隐藏时treeview会占用空间 using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using System.Collections;using IMSP.Sysmodule.Agent;namespace IMSP.Sysmodule.UIControl{ public class ComboBoxTreeView : ComboBox { private const int WM_LBUTTONDOWN = 0x201, WM_LBUTTONDBLCLK = 0x203; ToolStripControlHost treeViewHost; ToolStripDropDown dropDown; private TreeNode curnode; private Int32 keyid; private string showtext; TreeView treeView; public ComboBoxTreeView() { treeView = new TreeView(); treeView.AfterSelect += new TreeViewEventHandler(treeView_AfterSelect); treeView.BorderStyle = BorderStyle.None; treeViewHost = new ToolStripControlHost(treeView); dropDown = new ToolStripDropDown(); dropDown.Width = this.Width; dropDown.Items.Add(treeViewHost); this.TextChanged += new EventHandler(ComboBoxTreeView_TextChanged); } void ComboBoxTreeView_TextChanged(object sender, EventArgs e) { if (curnode != null) this.Text = curnode.Text; else this.Text = "无"; } public TreeNode CurrNode { get { return curnode; } set { curnode = value; } } public Int32 KeyId { get { return keyid; } set { keyid = value; try { foreach (OctrNode node in get_currnode_allson()) { if (node.Key == keyid) { curnode = node; TreeView.SelectedNode = node; this.Text = curnode.Text; return; } } } catch { }; curnode = null; this.Text = "无"; return; } } ArrayList tmpnode = new ArrayList(); private void set_curnode_alllist(OctrNode _curnode) { foreach (OctrNode node in _curnode.Nodes) { tmpnode.Add(node); set_curnode_alllist(node); } } public OctrNode[] get_currnode_allson() { tmpnode.Clear(); foreach (OctrNode _node in TreeView.Nodes) { //if (_inculdself) tmpnode.Add(curnode); tmpnode.Add(_node); set_curnode_alllist(_node); } OctrNode[] retnode = new OctrNode[tmpnode.Count]; tmpnode.CopyTo(retnode); return retnode; } public OctrNode[] get_currnode_allson(bool _inculdself) { tmpnode.Clear(); if (_inculdself) tmpnode.Add(curnode); foreach (OctrNode _node in curnode.Nodes) { tmpnode.Add(_node); set_curnode_alllist(_node); } OctrNode[] retnode = new OctrNode[tmpnode.Count]; tmpnode.CopyTo(retnode); return retnode; } public string ShowText { get { return showtext; } set { showtext = value; } } public void treeView_AfterSelect(object sender, TreeViewEventArgs e) { curnode = TreeView.SelectedNode; this.Text = curnode.Text; try { keyid = ((OctrNode)curnode).Key; } catch { // keyid = 0; } dropDown.Close(); } public TreeView TreeView { get { return treeViewHost.Control as TreeView; } } private void ShowDropDown() { if (dropDown != null) { treeViewHost.Size = new System.Drawing.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); } }}一个组件,仅供参考。 程序自动锁屏 关于C#的性能问题一:很奇怪的 for循环,求解释 如何用C#实现窗口应用程序隐藏窗体? 一台机器测试服务器端和多个客户端时,多个客户端向服务器发送不同数据,在服务器端数据被覆盖 窗体间如何有效传递数据(兼顾安全性和代码长度)? C#读取Excel数据 问题? C#程序如何打开 word文档 如何在C#中用Api获得c盘的总空间、剩余空间? 都N天啦,我的水晶报表这个问题还没解决!!!! 有关打印的问题,菜鸟问题,高手低手都来看看啊 在WPF中,如何实现跨进程下,一个窗体总是悬挂在另外一个窗体之上。 动态关系图怎么实现,有现成的控件吗?
http://www.codeproject.com/Articles/3994/Custom-ComboBoxes-with-Advanced-Drop-down-Features
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using IMSP.Sysmodule.Agent;namespace IMSP.Sysmodule.UIControl
{
public class ComboBoxTreeView : ComboBox
{
private const int WM_LBUTTONDOWN = 0x201, WM_LBUTTONDBLCLK = 0x203;
ToolStripControlHost treeViewHost;
ToolStripDropDown dropDown;
private TreeNode curnode;
private Int32 keyid;
private string showtext;
TreeView treeView;
public ComboBoxTreeView()
{
treeView = new TreeView();
treeView.AfterSelect += new TreeViewEventHandler(treeView_AfterSelect);
treeView.BorderStyle = BorderStyle.None; treeViewHost = new ToolStripControlHost(treeView);
dropDown = new ToolStripDropDown();
dropDown.Width = this.Width;
dropDown.Items.Add(treeViewHost);
this.TextChanged += new EventHandler(ComboBoxTreeView_TextChanged);
} void ComboBoxTreeView_TextChanged(object sender, EventArgs e)
{
if (curnode != null)
this.Text = curnode.Text;
else
this.Text = "无";
} public TreeNode CurrNode
{
get { return curnode; }
set { curnode = value; }
} public Int32 KeyId
{
get { return keyid; }
set
{
keyid = value;
try
{
foreach (OctrNode node in get_currnode_allson())
{
if (node.Key == keyid)
{
curnode = node;
TreeView.SelectedNode = node;
this.Text = curnode.Text;
return;
}
}
}
catch { };
curnode = null;
this.Text = "无";
return;
}
} ArrayList tmpnode = new ArrayList();
private void set_curnode_alllist(OctrNode _curnode)
{
foreach (OctrNode node in _curnode.Nodes)
{
tmpnode.Add(node);
set_curnode_alllist(node);
}
}
public OctrNode[] get_currnode_allson()
{
tmpnode.Clear(); foreach (OctrNode _node in TreeView.Nodes)
{
//if (_inculdself) tmpnode.Add(curnode);
tmpnode.Add(_node);
set_curnode_alllist(_node);
}
OctrNode[] retnode = new OctrNode[tmpnode.Count];
tmpnode.CopyTo(retnode);
return retnode;
} public OctrNode[] get_currnode_allson(bool _inculdself)
{
tmpnode.Clear();
if (_inculdself) tmpnode.Add(curnode);
foreach (OctrNode _node in curnode.Nodes)
{
tmpnode.Add(_node);
set_curnode_alllist(_node);
}
OctrNode[] retnode = new OctrNode[tmpnode.Count];
tmpnode.CopyTo(retnode);
return retnode;
} public string ShowText
{
get { return showtext; }
set { showtext = value; }
} public void treeView_AfterSelect(object sender, TreeViewEventArgs e)
{
curnode = TreeView.SelectedNode;
this.Text = curnode.Text;
try
{
keyid = ((OctrNode)curnode).Key;
}
catch
{
// keyid = 0;
}
dropDown.Close();
}
public TreeView TreeView
{
get { return treeViewHost.Control as TreeView; }
}
private void ShowDropDown()
{
if (dropDown != null)
{
treeViewHost.Size = new System.Drawing.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);
}
}
}
一个组件,仅供参考。