Fill Textbox with Bindingsource values Move to next and Previous, last and first

Asked

Viewed 64 times

1

Boa noite Galera,

I have a problem in a project in c# where I need to navigate in a bindingSource and fill the form fields with the values referring to the position of the bindingSource, i’ve already filled it all right problem ta when I go to the next record it from the error in the textbox saying that already has association follow the message "this generates two associations in the collection to link to the same property", below follows the code

private void btnProximo_Click(object sender, EventArgs e)
    {
        if (bindingSourcePais.Position + 1 < bindingSourcePais.Count)
        {
            try
            {
                proximo();

            }
            catch (Exception ex)
            {
                Util_Msg.erro(ex.Message);
            }

        }

    }

    private void proximo()
    {
        bindingSourcePais.MoveNext();
        txtCodigo.DataBindings.Add("Text", bindingSourcePais, "codigo");
        txtNome.DataBindings.Add("Text", bindingSourcePais, "nome");

    }
  • 1

    Take the code from the DataBindings.Add from within the method you perform every time you click the button. You just need to associate the control with the bindingSource once

  • Good evening @Rovannlinhalis, it worked your tip, I did not know this detail thank you

No answers

Browser other questions tagged

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