How to find a value of some column from DataView.CurrentItem.
Asked
Active
Viewed 1.6k times
1
-
1There is no DataView member named CurrentItem. Do you mean DataView indexer? Or a DataGrid.CurrentRow or DataGridView.CurrentRow? – Paul Williams Sep 16 '09 at 22:03
-
Sorry it is not DataView.CurrentItem it is CollectionViewSource.CurrentItem – Nadeem Shukoor Sep 16 '09 at 22:14
-
I figured out now I am using dt.Rows[CollectionViewSource.CurrentPosition]["ColumnName"].ToString(), is there a better way to do the same – Nadeem Shukoor Sep 16 '09 at 22:15
1 Answers
2
As Paul pointed out in his comment, there is no CurrentItem
member in the DataView
class.
If you know the index of the item, you can access a column by its name as shown below :
string name = dataView[index]["Name"] as string;
Similarly, if you have an instance of a DataRowView
(a view of a DataRow
), you can do that :
string name = dataRowView["Name"] as string;
EDIT: I just noticed the WPF tag on your question... perhaps you're talking about a CollectionView
, not DataView
?
CollectionView
doesn't have "columns" per se, but it can be represented in a GridView
or DataGrid
(which both have columns). It's just a view over a collection of objects. To access a specific field or property of the current object, there are two main options :
- if you statically know the actual type of the collection items : cast the
CurrentItem
to that type, and directly access the members you need - if you don't know the type, you can use reflection on the CurrentItem to access its properties or fields by name

Thomas Levesque
- 286,951
- 70
- 623
- 758
-
Thanks a lot, I am using following dt.Rows[CollectionViewSource.CurrentPosition]["ColumnName"].ToString() where colloectionViewSource is bound to DataContext . – Nadeem Shukoor Sep 17 '09 at 00:03