How to update dataGridView by clicking a button?

Asked

Viewed 1,730 times

2

I’m using an interface where I have the menustrip left and other form to the right, from there on menustrip has the options to novo(form charges nvCli) and busca(form charges nvConsCli), I need when the user presses the option busca he updates the dataGridView form(nvConsCli) which will open, because if the user has just registered a record he already appears in gridView

I tried with the following code:

nvConsCli.clientesTableAdapter.Fill(nvConsCli.regDataSet.clientes);

And another series of codes, but it doesn’t work, it doesn’t reload the data from the database and put it on dataGridView

2 answers

1

Create a method that only populates your dataGridView, then, in the event of the search button, call this method at the end, so that whenever the event fetches, the dataGridView will be updated with the data. If I can post the code I can reply with the appropriate changes.

1

This way you ensure that every change in the Dataset is automatically applied to the Datagrid :

            ... // 1)Carregar seu DataSet 

            // 2) Criar um BindingSource
            BindingSource bs = new BindingSource(); 

            // 3 ) Relacionar o BS com seu DataSet
            bs.DataSource = idDoSeuDataSet; 

            //4) Relacionar o Grid com seu BindingSource 
            idDoSeuGridView.DataSource = bs; 

Update in the Click event

Browser other questions tagged

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