title: C# Winform: Convert Combobox ValueMember Property to long
body: <p>I have a combobox with Id,Name columns. I have added these values to combobox with datatable:</p>
  
  <pre><code>        DataTable.Rows.Add(1, "Name1");
          DataTable.Rows.Add(2, "Name2");
  </code></pre>
  
  <p>Id column should be a long. However when I tried to get the Id value, it says cannot convert to long:</p>
  
  <pre><code>long id;
  id = this.comboBox1.ValueMember;
  </code></pre>
  
  <p>How to do that ?</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p>@BlueMonkMN, almost there but when I tried MessageBox.Show prints 1 (from my datatable values above)</p>
  
  <pre><code>        MessageBox.Show(comboBox1.SelectedValue.ToString());
  </code></pre>
  
  <p>but this line            </p>
  
  <pre><code>    id = (long)(comboBox1.SelectedValue);
  </code></pre>
  
  <p>throws a cast exception ?</p>
  
  <p>Why 1 cannot be converted to long ?</p>