title: Adding Data to a ComboBox (Not bound data)
body: <p>I wish to add data to a comboboxlist but am unsure of the correct method in which to do this. The data comes from a raw SQL statement. </p>
  
  <p>I have looked at the binding data directly from the database but it is not clear how all this binding and datasets work for me so I have decided to skip this and insert the data to the combox myself (with your help).</p>
  
  <p>The code i have see online goes like the following:</p>
  
  <pre><code>public partial class Form1 : Form {
      // Content item for the combo box
      private class Item {
          public string Name;
          public int Value;
          public Item(string name, int value) {
              Name = name; Value = value;
          }
          public override string ToString() {
              // Generates the text shown in the combo box
              return Name;
          }
      }
      public Form1() {
          InitializeComponent();
          // Put some stuff in the combo box
          comboBox1.Items.Add(new Item("Blue", 1));
          comboBox1.Items.Add(new Item("Red", 2));
          comboBox1.Items.Add(new Item("Nobugz", 666));
      }
  
      private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
          // Display the Value property
          Item itm = (Item)comboBox1.SelectedItem;
          Console.WriteLine("{0}, {1}", itm.Name, itm.Value);
      }
  }
  </code></pre>
  
  <p>Do you really have to create a new class to just to add data to a combobox ?
  Also, using the above technique my code looks like:</p>
  
  <pre><code>    while (rdata.Read()){
          String Name = (String)rdata["vetName"];
          Name = Name.Trim();
          String Surname = (String)rdata["vetSurname"];
          Surname = Surname.Trim();
  
          String id = rdata["vetID"].ToString().Trim();
  
          MessageBox.Show("ID " + id);
  
          int value1 = Convert.ToInt32(id);
          MessageBox.Show("value1 " + value1);
  
          String display = (String)Name + " " + Surname;
  
          editVetComboBox.Items.Add(new Item(display, 2));
      }
  </code></pre>
  
  <p>The problem is that while the combobox is populated  with firstname and surname <strong>the value (ID) is not added.</strong> </p>
  
  <p>Any Ideas ?</p>
  
  <p>Many Thanks,
  Richard</p>