I am trying to convert an inputted string to an int. I have tried int.parse, and int.parse32 but when I press "enter" I get the following error:
System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options,
NumberBuffer & number...."
partial class Form1:
this.orderID.Text = currentID;
this.orderID.KeyPress += new KeyPressEventHandler(EnterKey);
partial class Form1:Form:
public int newCurrentID;
private void EnterKey(object o, KeyPressEventArgs e)
{
if(e.KeyChar == (char)Keys.Enter)
{
try
{
newCurrentID = int.Parse(currentID);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
e.Handled = true;
}
}
EnterKeyand see whatcurrentIDcontains.Int.TryParse(orderID.Text, out someInt);orderID.Textis copied intocurrentID. You do have that, don't you?