Getting Value from DataView C#

匆匆过客 提交于 2019-12-25 00:23:49

问题


How to find a value of some column from DataView.CurrentItem.


回答1:


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


来源:https://stackoverflow.com/questions/1435734/getting-value-from-dataview-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!