<p>Here's the situation:  I need to bind a WPF <code>FixedPage</code> against a <code>DataRow</code>.  Bindings don't work against <code>DataRows</code>; they work against <code>DataRowViews</code>.  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 <code>DataRow</code>.  </p>

<p>What I need is to be able to get a <code>DataRowView</code> for a given <code>DataRow</code>.  I can't use the <code>Find()</code> method on the <code>DefaultView</code> because that takes a key, and there is no guarantee the table will have a primary key set.</p>

<p>Does anybody have a suggestion as to the best way to go around this?  </p>

[{'answer_id': 32483, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<pre><code>row.Table.DefaultView[row.Table.Rows.IndexOf(row)]\n</code></pre>\n\n<p>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.</p>\n'}, {'answer_id': 6989851, 'author': 'Joel Barsotti', 'author_id': 37154, 'author_profile': 'https://Stackoverflow.com/users/37154', 'pm_score': 4, 'selected': True, 'text': "<p>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.</p>\n\n<pre><code>        DataRowView newRowView = null;\n        foreach (DataRowView tempRowView in myDataTable.DefaultView)\n        {\n            if (tempRowView.Row == rowToMatch)\n                newRowView = tempRowView;\n        }\n        if (newRow != null)\n            UseNewRowView(newRowView);\n        else\n            HandleRowNotFound();\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/32460', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']