How to generate an automatic sequential number in C #

0

Good afternoon ..

I have a txtbox1.Tex in my form, and I need to generate a 2-digit sequential number automatically. EX 01, 02, 03 and so on, and it shows in txtbox.

Someone could help me.

Thank you.

    
asked by anonymous 13.06.2017 / 20:19

2 answers

0

In the form:

private int _contador = 0;

In the method in which you will change the text:

this._contador++;
this.txtBox1.Text = this._contador.ToString().PadLeft(2, '0');

The PadLeft method class String receives two parameters. The first one says the minimum length you want to have, and the second one says which character you are going to fill in on the left.

    
13.06.2017 / 20:27
-2

Good morning, I tried to do it here in my system and I could not, it does not appear the numbering in my textbox, I put it in the method:

private void txtnumvenpdv_TextChanged(object sender, EventArgs e)
{
    this._contador++;
    this.txtnumvenpdv.Text = this._contador.ToString().PadLeft(2, '0');
}
    
15.11.2018 / 12:24