Getting Started with Windows Forms ComboDropDown
18 Nov 201810 minutes to read
ComboDropDown can host any Windows Forms control in its drop-down area. This section explains how to get started with the WinForms ComboDropDown control by hosting a TreeView control in its drop-down, which is one of the most common use cases.
Assembly deployment
Refer to the Control Dependencies section for the list of assemblies and NuGet packages required to use the ComboDropDown control.
Refer to NuGet Packages to learn how to install NuGet packages in a Windows Forms application.
To install the required NuGet package using the NuGet Package Manager Console, run the following command:
Install-Package Syncfusion.Shared.Base
Adding ComboDropDown via Designer
-
Add the
Syncfusion.Shared.Baseassembly reference to the project. -
Create a new Windows Forms application in Visual Studio. Then, drag a
ComboDropDowncontrol and aTreeViewcontrol from the Toolbox onto the form.


- Add a few
TreeNodeentries to theTreeViewcontrol, either through the Properties window or in code. Set theTreeView.HideSelectionproperty tofalseso that the selected node remains highlighted when theTreeViewloses focus.

- Select the
ComboDropDowncontrol, and in the Properties window, set thePopupControlproperty to theTreeViewcontrol.

NOTE: To enable two-way interaction between the
ComboDropDownand theTreeViewcontrols, where selecting a node updates the text and editing the text selects a node, refer to Setting Interaction between ComboDropDown and TreeView.
Adding ComboDropDown through code
Add the ComboDropDown control programmatically by following the steps below.
-
Add the
Syncfusion.Shared.Baseassembly reference to the project and include theSyncfusion.Windows.Forms.Toolsnamespace in the code.using Syncfusion.Windows.Forms.Tools;Imports Syncfusion.Windows.Forms.Tools -
Create an instance of the
ComboDropDowncontrol.private Syncfusion.Windows.Forms.Tools.ComboDropDown comboDropDown1; this.comboDropDown1 = new Syncfusion.Windows.Forms.Tools.ComboDropDown();Private comboDropDown1 As Syncfusion.Windows.Forms.Tools.ComboDropDown Me.comboDropDown1 = New Syncfusion.Windows.Forms.Tools.ComboDropDown() -
Initialize the
TreeViewcontrol with sample nodes, and then assign it to thePopupControlproperty of theComboDropDowncontrol.
// Populate the TreeView with sample nodes
this.treeView1.Nodes.Add("Root");
this.treeView1.Nodes[0].Nodes.Add("Child 1");
this.treeView1.Nodes[0].Nodes.Add("Child 2");
this.treeView1.HideSelection = false;
// Host the TreeView in the ComboDropDown's popup
this.comboDropDown1.PopupControl = this.treeView1;' Populate the TreeView with sample nodes
Me.treeView1.Nodes.Add("Root")
Me.treeView1.Nodes(0).Nodes.Add("Child 1")
Me.treeView1.Nodes(0).Nodes.Add("Child 2")
Me.treeView1.HideSelection = False
' Host the TreeView in the ComboDropDown's popup
Me.comboDropDown1.PopupControl = Me.treeView1- Add the
ComboDropDownandTreeViewcontrols to the form’sControlscollection.
this.Controls.Add(this.comboDropDown1);
this.Controls.Add(this.treeView1);Me.Controls.Add(Me.comboDropDown1)
Me.Controls.Add(Me.treeView1)Complete Code Example
The following example combines all the preceding steps into a single runnable application.
using Syncfusion.Windows.Forms.Tools;
public partial class Form1 : Form
{
private Syncfusion.Windows.Forms.Tools.ComboDropDown comboDropDown1;
private System.Windows.Forms.TreeView treeView1;
public Form1()
{
InitializeComponent();
this.comboDropDown1 = new Syncfusion.Windows.Forms.Tools.ComboDropDown();
this.treeView1 = new TreeView();
this.comboDropDown1.Location = new System.Drawing.Point(20, 20);
this.comboDropDown1.Size = new System.Drawing.Size(200, 21);
// Populate the TreeView with sample nodes
this.treeView1.Nodes.Add("Root");
this.treeView1.Nodes[0].Nodes.Add("Child 1");
this.treeView1.Nodes[0].Nodes.Add("Child 2");
this.treeView1.HideSelection = false;
// Host the TreeView in the ComboDropDown's popup
this.comboDropDown1.PopupControl = this.treeView1;
this.Controls.Add(this.comboDropDown1);
this.Controls.Add(this.treeView1);
}
}Imports Syncfusion.Windows.Forms.Tools
Public Partial Class Form1
Inherits System.Windows.Forms.Form
Private comboDropDown1 As Syncfusion.Windows.Forms.Tools.ComboDropDown
Private treeView1 As System.Windows.Forms.TreeView
Public Sub New()
InitializeComponent()
Me.comboDropDown1 = New Syncfusion.Windows.Forms.Tools.ComboDropDown()
Me.treeView1 = New TreeView()
Me.comboDropDown1.Location = New System.Drawing.Point(20, 20)
Me.comboDropDown1.Size = New System.Drawing.Size(200, 21)
' Populate the TreeView with sample nodes
Me.treeView1.Nodes.Add("Root")
Me.treeView1.Nodes(0).Nodes.Add("Child 1")
Me.treeView1.Nodes(0).Nodes.Add("Child 2")
Me.treeView1.HideSelection = False
' Host the TreeView in the ComboDropDown's popup
Me.comboDropDown1.PopupControl = Me.treeView1
Me.Controls.Add(Me.comboDropDown1)
Me.Controls.Add(Me.treeView1)
End Sub
End Class