How to bind a list in Winforms ComboDropdown control?
ComboDropdown is a combo box-like control that can host any control in the dropdown area. Here, the list cannot be bound directly. Instead, we can bind the list to the ListBox and host that ListBox in the dropdown using the PopupControl property.
The following code demonstrates how to bind a list in the ComboDropDown control.
C#
public Form1()
{
InitializeComponent();
this.listBox1.DataSource = this.GetData();
this.comboDropDown1.PopupControl = listBox1;
}
private List<string> GetData()
{
List<string> list = new List<string>();
list.Add("Alaska");
list.Add("Arizona");
list.Add("Colorado");
list.Add("Indiana");
list.Add("Iowa");
list.Add("Kansas");
list.Add("Kentucky");
list.Add("Louisiana");
list.Add("Maine");
list.Add("Maryland");
list.Add("Massachusetts");
list.Add("Michigan");
list.Add("Minnesota");
return list;
}Output
