How to calculate the sum of a TextBox from another TextBox in C# -


i want values integer number in textbox.

but don't know how convert textbox1.text int type.

it exception error like:

cannot implicitly convert type 'int' 'string'

my code like:

txtto.text = convert.toint32(txtfrom.text) + listviewitem1.items.count;

the error simple fix, add tostring result of addition

txtto.text = (convert.toint32(txtfrom.text) + listviewitem1.items.count).tostring(); 

but partial solution because, if user types not valid integer number, conversion int32 fail.

you need use int32.tryparse

int num; if(!int32.tryparse(txtfrom.text, out num)) {   messagebox.show("not valid number");   return; } txtto.text = (num + listviewitem1.items.count).tostring(); 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -