控件源码: using System.Data; using System.Text; using System.Windows.Forms; public class ComboBoxTreeView : ComboBox { private const int WM_LBUTTONDOWN = 0x201, WM_LBUTTONDBLCLK = 0x203; ToolStripControlHost treeViewHost; ToolStripDropDown dropDown; public ComboBoxTreeView() { TreeView 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); } public void treeView_AfterSelect(object sender, TreeViewEventArgs e) { this.Text=TreeView.SelectedNode.Text; 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); } } 下面是使用的用法: /// <summary> /// 初始化ComboBoxTree /// </summary> private void InitMcdTypeTree() { TreeView treeView = this.txtMcdType.TreeView; CSop_DataCompressor ds = sv_OrderMgr.ProductCate(); g_TreeDT = ds.Tables[0]; DataRow[] dataRow = g_TreeDT.Select(string.Format("colid='{0}'",CNST_TOPDPT)); if (dataRow.Length > 0) { TreeNode root = new TreeNode(); root.Text = dataRow[0]["colName"].ToString(); root.Name = dataRow[0]["colID"].ToString(); //增加树的根节点 treeView.Nodes.Add(root); root.ExpandAll(); addNode(root, root.Name); } } /// <summary> /// 递规添加TreeView节点 /// </summary> /// <param name="node"></param> /// <param name="parentID"></param> public void addNode(TreeNode node, string parentID) { DataRow[] dataRows = g_TreeDT.Select(string.Format("colPrtID='{0}'", parentID)); foreach (DataRow row in dataRows) { TreeNode subNode = new TreeNode(); subNode.Text = row["colName"].ToString(); subNode.Name = row["colID"].ToString(); node.Nodes.Add(subNode); addNode(subNode, subNode.Name); } } :