I would go one step further and simply create your own class for this. The ComboBox will call ToString to display the items, so your class can just override that method for display purposes, and expose an int property for backend data collection:
Now just add instances of the "Whatever" class to the ComboBox:Code:class Whatever { public Whatever( int years ) { Years = years; } public int Years { get; private set; } public override string ToString() { return String.Format( "{0} years", Years ); } }
Code:comboBox.Items.Add( new Whatever( 2 ) ); comboBox.Items.Add( new Whatever( 5 ) ); // ... // and to get them back... var item = (Whatever)comboBox.SelectedItem; int years = item.Years; // no parsing required




Reply With Quote