title: What is the best way to display one value and store another on .net comboboxes?
body: <p>I can't seem to find an easy to use, .net native way to get Comboboxes on .net winforms to display one value and return another based on the selection without creating my own helper class, with the knowledge that winforms is going to display the ToString method on the object that you put in it.</p>
  
  <p>This is how I'm doing it now, very generically. First, create the helper class.</p>
  
  <pre><code> Public Class ListItem
       Public Value As Object
       Public DisplayString As String
  
       Public Sub New(ByVal NewValue As Object, ByVal NewDisplayString As String)
           Value = NewValue
           DisplayString = NewDisplayString
       End Sub
  
       Public Overrides Function ToString() As String
           Return DisplayString
       End Function
   End Class
  </code></pre>
  
  <p>then, to load the combobox from a collection or whatever.</p>
  
  <pre><code>    For Each o as WhateverObject In CollectionIwantToaddItemsFrom
          li = New ListItem(o.ValueToReturn, o.ValueToDisplay)
          Me.ComboBox1.Items.Add(li)
      Next
  </code></pre>
  
  <p>and finally, to use the object</p>
  
  <pre><code>Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  if me.combobox1.selecteditem is nothing then exit sub
  Dim li As ListItem = me.ComboBox1.SelectedItem
  Dim o as object = li.value 
  'do stuff with o.
  end sub
  </code></pre>
  
  <p>I'm sure there is something I'm better to use in the framework that I'm over looking.  What is it?</p>