c# - 让 DataGridView 直观地反射(reflect)其 DataSource 中的变化的正确方法

标签 c# winforms ado.net datagridview

假设 DataGridView 将其 DataSource 属性设置为 DataView 实例。

DataGridView dgv;
DataTable dt;

// ... dt gets populated.

DataView dv = dt.DefaultView;

dgv.DataSource = dv;

// ... dt gets modified

// The DataGridView needs to update to show these changes visually
// What goes here?

我知道您可以将 dgv.DataSource 设置为 null,然后返回到 dv。但这似乎很奇怪。我敢肯定还有其他几种方法。但正确的官方方法是什么?

最佳答案

正确的方法是数据源实现IBindingList,为SupportsChangeNotification返回true,并且发出 ListChanged 事件。然而,据我所知,一个DataView 这个...

关于c# - 让 DataGridView 直观地反射(reflect)其 DataSource 中的变化的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/630343/

相关文章:

c# - ExecuteScalar 返回与纯 SQL 不同的结果

c# - 在哪里可以将 "Trim"添加到此 C# 语句?

C#:函数中的 'out' 参数可以是对象属性/变量吗?

c# - 当我显示另一个表单时,如何防止原始表单失去焦点?

c# - 用 Entity Framework 替换 ADO.NET。 Entity Framework 适用于以下场景吗?

c# - 是什么让 ADO.NET Entity Framework 与市场上的其他 ORM 不同?

c# - 将 IEnumerable<WebSocketHandler> 转换为 WebSocketCollection

c# - HLSL:返回一个 float4 数组?

c# - Windows Media Player - 播放完毕后隐藏播放器

c# - Designer 中 BeginInit() 和 EndInit() 方法的作用