Created
January 22, 2016 06:53
-
-
Save deapsquatter/aea78fc32241d9f64af3 to your computer and use it in GitHub Desktop.
Combobox Binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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