title: C# - retrieve the selected value from a combobox
body: <p>I have a comboBox with <code>ValueMember = ID</code> and <code>DisplayMember = Name</code>. I need the value that is associated with that name so I do something like this:</p>
  
  <pre><code>if (cboTypeOfMaterial.SelectedIndex != -1)
              {
                  string temp = cboTypeOfMaterial.SelectedValue.ToString();
                  //More code here...
              }
  </code></pre>
  
  <p>Which returns the <code>ID</code> value as a string. For example - "7". </p>
  
  <p>If I try :</p>
  
  <pre><code>if (cboTypeOfMaterial.SelectedIndex != -1)
                  {
                      string temp = cboTypeOfMaterial.DisplayMember.ToString();
                      //More code here...
                  }
  </code></pre>
  
  <p>I get the string <code>Name</code> which is the key. </p>
  
  <p>And what I need is to get the value of the selected element's <code>Name</code></p>