Refresh button - Refreshing data grid view after inserting, deleting, updating

前端 未结 6 1617
别跟我提以往
别跟我提以往 2020-12-02 00:59

I\'m trying to create a refresh button to automatically refresh the data inside my datagridview after i have finish updating them.

However, my refresh button doesn\'

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 01:38

    I had a datagridview, bound to a table in an Entity Framework database:

    dataGridView1.DataSource = MyDatabase.MyTable;
    

    It would never refresh despite two wasted days. I solved it with a simple workaround:

    private void button_refresh_Click(object sender, EventArgs e) {
        dataGridView1.DataSource = MyDatabase.MyTable.Where(i =>(true));
    }
    

    This is an ugly workaround, and friend explained me how it works - if I do just dataGridView1.DataSource = database.table, it will cache the table and use the cached data forever. The fact that each time we create a new dummy query, prevents .net from caching it.

提交回复
热议问题