转自
http://www.daveoncsharp.com/2009/11/binding-a-windows-forms-combobox-in-csharp/
private void MainForm_Load(object sender, EventArgs e)
{
// Create a List to store our KeyValuePairs
List<KeyValuePair<string, string>> data = new List<KeyValuePair<string, string>>();
// Add data to the List
data.Add(new KeyValuePair<string, string>("p1", "Joe"));
data.Add(new KeyValuePair<string, string>("p2", "David"));
data.Add(new KeyValuePair<string, string>("p3", "Keith"));
data.Add(new KeyValuePair<string, string>("p4", "Andrew"));
data.Add(new KeyValuePair<string, string>("p5", "Maria"));
// Clear the combobox
cboData.DataSource = null;
cboData.Items.Clear();
// Bind the combobox
cboData.DataSource = new BindingSource(data, null);
cboData.DisplayMember = "Value";
cboData.ValueMember = "Key";
}
private void cboData_SelectedIndexChanged(object sender, EventArgs e)
{
// Get the selected item in the combobox
KeyValuePair<string, string> selectedPair = (KeyValuePair<string, string>)cboData.SelectedItem;
// Show selected information on screen
lblSelectedKey.Text = selectedPair.Key;
lblSelectedValue.Text = selectedPair.Value;
}