简体   繁体   中英

c# how to refresh datagridview properly

I'm working on a project, in this project i need to use sql databases. I got a method for insertion and its working properly. But i want to refresh my datagridview after insertion with a Display() method.Now, there is the code:

 private void Display()
    {
        this.packetsTableAdapter.Fill(this.database1DataSet.Packets);           
        dataGridView1.Refresh();
    }        

What i have to do to fix it help plz.

You probably need to re-bind the dataset to gridview like

this.packetsTableAdapter.Fill(this.database1DataSet);           
dataGridView1.DataSource = null;
dataGridView1.DataSource = this.database1DataSet;

you must load dataGridView1.DataSource after add one item. look like this method:

 this.packetsTableAdapter.Fill(this.database1DataSet.Packets);//your code 
LoadData();

. . .

public void LoadData()
     {    
      dataGridView1.DataSource=// load data
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM