ObservableCollection / DataTable相关问题? [英] ObservableCollection/DataTable related question?

查看:95
本文介绍了ObservableCollection / DataTable相关问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


假设我有一个绑定到xamDatagrid的DataTable。在数据网格中,我有  AutoGenerateFields = True。


DataTable由"SELECT * FROM Customers"填充。现在,如果我在SQL中,我向表Customers添加一个新列,它将流入并显示在DataGrid中。


如果,而不是DataTable,假设我使用了的ObservableCollection<客户取代。然后,如果我向基础SQL表添加新列,它将不会流向数据网格。我将不得不向Customer类添加相应的属性并重新编译
并重新部署我的应用程序。


Q.如果我不想使用DataTable,我还有什么其他选择来实现上述目标?我还能用ObservableCollection做吗?


谢谢。


解决方案

您可以尝试从DataTable生成ObservableCollection。以下链接可能有所帮助


https://stackoverflow.com/a/27506660


Let's say I have a DataTable bound to a xamDatagrid. In the datagrid I have AutoGenerateFields=True.

The DataTable is populated by "SELECT * FROM Customers". Now, if my in SQL, I add a new column to the table Customers, it will flow though and show in the DataGrid.

If, instead of a DataTable, let's say I use an ObservableCollection<Customer>. Then, if I add a new column to underlying SQL table, it will not flow through to the datagrid. I will have to add corresponding property to class Customer and recompile and re-deploy my app.

Q. In case, I do not want to use a DataTable, what other option do I have to achieve the above? Can I still do it with an ObservableCollection?

Thanks.

解决方案

You can try generating ObservableCollection from DataTable. Following link may help

https://stackoverflow.com/a/27506660


这篇关于ObservableCollection / DataTable相关问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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