从 DataRow 获取 DefaultView DataRowView [英] Get the DefaultView DataRowView from a DataRow
问题描述
情况如下:我需要将 WPF FixedPage
与 DataRow
绑定.绑定对 DataRows
不起作用;它们对 DataRowViews
起作用.我需要以最通用的方式执行此操作,因为我对 DataRow
中的内容一无所知,也无法控制.
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
.
我需要的是能够为给定的 DataRow
获取 DataRowView
.我不能在 DefaultView
上使用 Find()
方法,因为它需要一个键,并且不能保证表会有一个主键集.
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?
推荐答案
不完全是一段性感的代码,但它们似乎不是一种无需循环表格即可自动查找行的方法.
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.
DataRowView newRowView = null;
foreach (DataRowView tempRowView in myDataTable.DefaultView)
{
if (tempRowView.Row == rowToMatch)
newRowView = tempRowView;
}
if (newRow != null)
UseNewRowView(newRowView);
else
HandleRowNotFound();
这篇关于从 DataRow 获取 DefaultView DataRowView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!