How to generate an automatic sequential number in C#

Asked

Viewed 2,041 times

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 shows in txtbox.

Could someone help me.

Thank you.

  • 2

    Could post what has already been developed?

2 answers

0


On 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 method PadLeft class String receives two parameters. The first tells you the minimum length you wish to have, and the second tells you which character you will fill out on the left.

  • Renan thank you very much, solved part of my problem now I need to sequence the code. vlw

-1

Create a Genero method

private void Gerar()
{
  // Gerando Código Incremento
   this._contador++;
   this.Codigo.Text = this._contador.ToString().PadLeft(2, '0');
 }

in Lod

 private void Cliente_Load(object sender, EventArgs e)
  {

            Gerar();

  }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.