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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -