Get the DefaultView DataRowView from a DataRow
12,914
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();
Author by
Admin
Updated on June 08, 2022Comments
-
Admin almost 2 years
Here's the situation: I need to bind a WPF
FixedPage
against aDataRow
. Bindings don't work againstDataRows
; they work againstDataRowViews
. I need to do this in the most generic way possible, as I know nothing about and have no control over what is in theDataRow
.What I need is to be able to get a
DataRowView
for a givenDataRow
. I can't use theFind()
method on theDefaultView
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?
-
Admin over 11 yearsHey, it only took me 4-5 years.