Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDictionary<int, string> comboDictionary = new Dictionary<int, string>();
- private void Form1_Load(object sender, EventArgs e)
- {
- /*comboBox1.Items.Add("name");
- comboBox1.Items.Add("cni");
- comboBox1.Items.Add("ip");
- comboBox1.Items.Add("maroc");
- comboBox1.SelectedItem = 0;
- */
- comboDictionary.Add(1, "first");
- comboDictionary.Add(2, "second");
- comboDictionary.Add(3, "third");
- comboBox1.DataSource = comboDictionary.ToList();
- comboBox1.DisplayMember = "Value";
- comboBox1.ValueMember = "Key";
- }
- private void Button1_Click(object sender, EventArgs e)
- {
- //MessageBox.Show(comboBox1.Items[comboBox1.SelectedIndex].ToString());
- comboBox1.Items[comboBox1.SelectedIndex].ToString();
- var control = ((KeyValuePair<int, string>)comboBox1.SelectedItem).Key;
- MessageBox.Show(control.ToString());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement