Number of Columns a DataRowView has?

1.3k views Asked by At

I have a method SelectedRow() that grabs the content of a selected DataGrid row

private System.Data.DataRowView SelectedRow()
{
    System.Data.DataRowView row = (System.Data.DataRowView)dgBrokerages.SelectedItems[0];
    return row;            
}

and would like to know how I can obtain an int containing the number of Columns that row contains.

private int NumColumns()
{
    System.Data.DataRowView row = SelectedRow();
    return row.Length; // <- Something like that
}

I'm basically looking for if there is a row.Length or row.Size?

Thanks, iato

1

There are 1 answers

1
Mikhail Tumashenko On BEST ANSWER

Try this:

private int NumColumns()
{
    System.Data.DataRowView row = SelectedRow();
    return row.Row.Table.Columns.Count;
}