I have a dataview defined as:
DataView dvPricing = historicalPricing.GetAuctionData().DefaultView;
This is what I have tried, but it returns the name, not the value in the column:
dvPricing.ToTable().Columns["GrossPerPop"].ToString();
Following are the methods of a DataView: Find : Parameter: An array of values; Value Returned: Index of the row. FindRow : Parameter: An array of values; Value Returned: Collection of DataRow. AddNew : Adds a new row to the DataView object.
A DataView enables you to create different views of the data stored in a DataTable, a capability that is often used in data-binding applications. Using a DataView, you can expose the data in a table with different sort orders, and you can filter the data by row state or based on a filter expression.
You can access the DataRow that is exposed by the DataRowView through the Row property of the DataRowView. When you view values by using a DataRowView, the RowStateFilter property determines which row version of the underlying DataRow is exposed.
DataView. Table. Copy() will copy the source DataTable, not the filtered data of the DataView.
You need to use a DataRow
to get a value; values exist in the data, not the column headers. In LINQ, there is an extension method that might help:
string val = table.Rows[rowIndex].Field<string>("GrossPerPop");
or without LINQ:
string val = (string)table.Rows[rowIndex]["GrossPerPop"];
(assuming the data is a string... if not, use ToString()
)
If you have a DataView
rather than a DataTable
, then the same works with a DataRowView
:
string val = (string)view[rowIndex]["GrossPerPop"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With