Check if WPF DataRowView contains a column

Sam picture Sam · Dec 12, 2010 · Viewed 7.3k times · Source

I can get the value of a column in a DataRowView using

DataRowView row;
object value = row["MyColumn"];

of course, if there is no "MyColumn" in the DataRowView, this code throws an exception.

How do I check in advance, if the row contains "MyColumn"? Sadly there is no row.Contains("MyColumn") on DataRowView.

Answer

Fredrik Hedblad picture Fredrik Hedblad · Dec 12, 2010

You can use this

dataRowView.Row.Table.Columns.Contains("MyColumn")