The Property SelectedItem does not return an
Item, it returns an
Object. MSDN reference for the SelectedItem property -
MSDN - ComboBox.SelectedItem Property[
^]
You could change your code as follows;
string strItemText = comboBox1.Text;
decimal decItemValue;
if(!Decimal.TryParse(comboBox1.SelectedValue.ToString(), out decItemValue))
{
}
Use your debugger, between reference information - MSDN is great but there are others - and your debugger you will learn more about coding than you think
Your code;
var item = (Item)ComboBox.SelectedItem;
is attempting to unbox an object to a value type, this only works for explicit conversions, if the conversion is not explicit then the conversion will fail - refer;
Boxing and Unboxing (C# Programming Guide) | Microsoft Docs[
^]
C# is a type-strong language & you should use the correct type for variables - IMO. In this case I would see the variable type "var" and assume you were being lazy. There is a use for the var type but this is not it - refer;
var (C# Reference) | Microsoft Docs[
^]
Kind Regards