最好的方式来刷新的DataGridView在更新基础数据源 [英] Best way to refresh DataGridView when you update the base data source

查看:1089
本文介绍了最好的方式来刷新的DataGridView在更新基础数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是刷新一个DataGridView在更新基础数据源的最佳方式是什么?

我经常更新数据源,并想显示的结果给用户,因为它发生。

我有这样的事情做(和它的作品),但null'ing了 DataGridView.DataSource 似乎不是正确的方式。

 名单,其中,ItemState> itemStates =新的名单,其中,ItemState>();
dataGridView1.DataSource = itemStates;

的for(int i = 0;我小于10;我++){
    itemStates.Add(新ItemState {标识= i.ToString()});
    dataGridView1.DataSource = NULL;
    dataGridView1.DataSource = itemStates;
    System.Threading.Thread.Sleep(500);
}
 

解决方案

那么,它没有得到比这更好。据官方统计,你应该使用

  dataGridView1.DataSource =的typeof(名单);
dataGridView1.DataSource = itemStates;
 

这仍然是一个清除/复位源之类的解决方案,但我还没有找到任何东西,将可靠地刷新DGV数据源。

What is the best way to refresh a DataGridView when you update the base data source?

I'm updating the datasource frequently and wanted to display the outcome to the user as it happens.

I've got something like this made (and it works), but null'ing out the DataGridView.DataSource doesn't seem like the right way.

List<ItemState> itemStates = new List<ItemState>();
dataGridView1.DataSource = itemStates;

for (int i = 0; i < 10; i++) { 
    itemStates.Add(new ItemState { Id = i.ToString() });
    dataGridView1.DataSource = null;
    dataGridView1.DataSource = itemStates;
    System.Threading.Thread.Sleep(500);
}

解决方案

Well, it doesn't get much better than that. Officially, you should use

dataGridView1.DataSource = typeof(List); 
dataGridView1.DataSource = itemStates;

It's still a "clear/reset source" kind of solution, but I have yet to find anything else that would reliably refresh the DGV data source.

这篇关于最好的方式来刷新的DataGridView在更新基础数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆