从 DataRow 获取 DefaultView DataRowView
情况如下:我需要将 WPF FixedPage
与 DataRow
绑定。 绑定不适用于DataRows
; 它们针对 DataRowViews
工作。 我需要以最通用的方式执行此操作,因为我对 DataRow 中的内容一无所知,也无法控制。
我需要的是能够获取给定 DataRow
的 DataRowView
。 我无法在 DefaultView
上使用 Find()
方法,因为它需要一个键,并且不能保证该表将具有主键集。
有人对解决这个问题的最佳方法有建议吗?
Here's the situation: I need to bind a WPF FixedPage
against a DataRow
. Bindings don't work against DataRows
; they work against DataRowViews
. I need to do this in the most generic way possible, as I know nothing about and have no control over what is in the DataRow
.
What I need is to be able to get a DataRowView
for a given DataRow
. I can't use the Find()
method on the DefaultView
because that takes a key, and there is no guarantee the table will have a primary key set.
Does anybody have a suggestion as to the best way to go around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不完全是一段性感的代码,但它们似乎不是一种无需循环表即可自动查找行的方法。
Not Exactly a sexy piece of code but their doesn't seem to be an automated way to find the row without just looping the table.
这是一个好的答案。 但是,如果您发现自己处于这种情况,您应该考虑更多地了解 DataView 及其使用方式,然后将代码重构为以视图为中心而不是以表为中心。
This is an okay answer. But if you find yourself in this situation, you should consider learning more about DataViews and how they are used, then refactor your code to be view-centric rather than table-centric.