Skip to content

Instantly share code, notes, and snippets.

@deapsquatter
Created January 22, 2016 06:53
Show Gist options
  • Save deapsquatter/aea78fc32241d9f64af3 to your computer and use it in GitHub Desktop.
Save deapsquatter/aea78fc32241d9f64af3 to your computer and use it in GitHub Desktop.
Combobox Binding
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.DisplayMember = "Value";
comboBox1.ValueMember = "Key";
var dic = new Dictionary<int, string>();
dic.Add(1, "hello");
dic.Add(2, "goodbye");
comboBox1.DataSource = new BindingSource(dic, null);
}
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null)
MessageBox.Show(comboBox1.SelectedValue.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment