Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am incrementing combo box value with given quantity in textbox like this

C#
decimal j = Convert.ToDecimal(cbxgetSN.Text);

Int64 k = Convert.ToInt64(textBoxQuantitySN.Text);

for (int i = 0; i < k; i++)
{

   SerialListBox.Items.Add("RET"+(j + i + 1));

}

and this
but if my combobox value is 000123 then it only increment 123
at the moment its doing.
123
124
125
126
i want it to incement like.
000123
000124
000125
please help
Posted
Updated 4-Mar-13 22:12pm
v2
Comments
madhuri@mumbai 5-Mar-13 4:27am    
You can manully add zero before string.

1 solution

You need to format it as a string, rather than leave it as an int. Ints have no concept of leading zeros, so unless you format it, it can't "keep any zeros" at the front.
Try:
C#
string s = myIntValue.ToString("D6");
 
Share this answer
 
Comments
ByakuyaKuchiki 5-Mar-13 4:24am    
how and where must i use
string s = myIntValue.ToString("D6");
OriginalGriff 5-Mar-13 4:43am    
I would have to guess (since you don't specify what you are doing with it that well, but probably what you want is to replace:
SerialListBox.Items.Add("RET"+(j + i + 1));
With:
SerialListBox.Items.Add("RET"+(j + i + 1).ToString("D6"));
Or better:
SerialListBox.Items.Add(string.Format("RET{0:D6}", j + i + 1));
ByakuyaKuchiki 5-Mar-13 7:41am    
i have one combo box one textbox and one listbox.
my combobox has value 002 or 001 any thind with zero in the begining.
my textbox have quantity number. how many times the value in combobox will increment . and the result will be shown in listbox.
and the iam using top code to do all this.
now my code is not incrementing any value which statrs with zero.
it skip zero and increment rest.
i want it must increment like
001
002
003
not
1
2
3
and leave zero behind
OriginalGriff 5-Mar-13 7:49am    
And did you try the code I gave you?
ByakuyaKuchiki 5-Mar-13 8:01am    
i am getin error "formate specifier was invalid" for these codes
SerialListBox.Items.Add("RET"+(j + i + 1).ToString("D6"));
SerialListBox.Items.Add(string.Format("RET{0:D6}", j + i + 1));

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