Click here to Skip to main content
16,011,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
sir i wanted to auto increment the textbox2.text as it is used for invoice no. i wanted to increment from 1000 and please help me how can i increment.

Thanks inadvance and i am new to software developing i hope little help from members n my heartly wishes to Very happy new year 2012.
Posted

Although you can, I wouldn't do it.

Doing it that way relies on the user not modifying the value and inserting a non-numeric value.

The easiest way is to keep the current invoice number as a class level integer variable, and increment it when necessary and re-write the contents of the text box.
C#
private int invoiceNumber = 1000;
...
private void NextInvoice()
   {
   invoiceNumber++;
   TextBoxForInvoiceNumber.Text = invoiceNumber.ToString("000000");
   }

But I would use either a Label instead of a TextBox, or make the TextBox ReadOnly property true.

If you must use the TextBox content, you have to do:
C#
private void NextInvoice()
   {
   int invoiceNumber = int.Parse(TextBoxForInvoiceNumber.Text);
   invoiceNumber++;
   TextBoxForInvoiceNumber.Text = invoiceNumber.ToString("000000");
   }

And remember to add error trapping and so forth to prevent your app falling over when the user makes a small mistake...
 
Share this answer
 
Comments
karthikh87 31-Dec-11 14:59pm    
MR. OriginalGriff..
i could not understand what actually you mean to say.. i am new to this so can u elaborate and i wanted to know what is ... mean which you mentioned and can u please tell where exactly i have to write that code and can u please explain in detail i request you thanks in advance for the interest you should to resolve my problem..
OriginalGriff 31-Dec-11 15:57pm    
It's difficult to elaborate on two lines of code...:laugh:
What exactly are you trying to achieve? Not "what code do you need?" but "What are you trying to do? Why are you using a textbox to hold a number, and why are you incrementing it?"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900