Guest User

Untitled

a guest
Aug 25th, 2019
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. IDictionary<int, string> comboDictionary = new Dictionary<int, string>();
  2.  
  3. private void Form1_Load(object sender, EventArgs e)
  4. {
  5. /*comboBox1.Items.Add("name");
  6. comboBox1.Items.Add("cni");
  7. comboBox1.Items.Add("ip");
  8. comboBox1.Items.Add("maroc");
  9. comboBox1.SelectedItem = 0;
  10. */
  11. comboDictionary.Add(1, "first");
  12. comboDictionary.Add(2, "second");
  13. comboDictionary.Add(3, "third");
  14. comboBox1.DataSource = comboDictionary.ToList();
  15. comboBox1.DisplayMember = "Value";
  16. comboBox1.ValueMember = "Key";
  17.  
  18. }
  19.  
  20. private void Button1_Click(object sender, EventArgs e)
  21. {
  22. //MessageBox.Show(comboBox1.Items[comboBox1.SelectedIndex].ToString());
  23. comboBox1.Items[comboBox1.SelectedIndex].ToString();
  24. var control = ((KeyValuePair<int, string>)comboBox1.SelectedItem).Key;
  25.  
  26. MessageBox.Show(control.ToString());
  27.  
  28. }
RAW Paste Data