gpt4 book ai didi

c# - 将 DataGrid 绑定(bind)到两个 DataTable

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:46 26 4
gpt4 key购买 nike

我有两个 DataTable,具有完全相同的结构、模式和约束,但行不同。

我需要的是将这些表显示到一个 DataGrid 中,连接起来,即首先是第一个 DataTable 的行,然后是第二个的行。

我不想加入、合并或任何创建新 DataTable 对象的操作,因为我需要在 DataGrid 中显示对两个原始对象的更改>(还有另一个方向:如果用户在 DataGrid 中修改某些内容,我希望更新两个原始 DataTable)。

所以我想我需要的是一种“代理”,比如两个 DataTable 上的 DataView,但我不知道这是否可行。

最佳答案

proxy", like a DataView on the two DataTable,

我建议创建一个向量类实体,它具有要显示的列的所有属性。但是此类实体将保留对原始数据的引用。将两个 DataTable 提取到这个新对象的一个​​列表中并绑定(bind)到该列表。

要处理更改,让类遵守 INotifyPropertyChange 并创建一个数据管理器,它将订阅每个实例的属性更改。当管理器检测到更改时,它会将更改推回原始数据表的行。

public class DataVector : INotifyPropertyChange
{
public DataTable OriginationDataTable { get; set; }
public int OrininationRow { get; set; }

// Mirror the properties
public string Name { get {} { _Name = value; NotifyChange("Name"); }


// CTORs which help create this object
public DataVector(DataTable dt, int originatingRow) { ... }

....
}

关于c# - 将 DataGrid 绑定(bind)到两个 DataTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32630884/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com