Converting String to Int C# -
i trying convert inputted string int. have tried int.parse, , int.parse32 when press "enter" following error:
system.formatexception: input string not in correct format. @ 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; } }
string immutable when assign currentid
textbox changes of text not reflected in variable currentid
this.orderid.text = currentid;
what need in enterkey
function use textbox value directly:
private void enterkey(object o, keypresseventargs e) { if(e.keychar == (char)keys.enter) { if(!int.tryparse(orderid.text, out newcurrentid)) messagebox.show("not number"); e.handled = true; } }
Comments
Post a Comment