Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
How to get the PropertyInfo for a DataRow from its PropertyDescriptor.
//pd is a PropertyDescriptor
var propertyinfo = pd.ComponentType.GetProperty(pd.Name);
the above code works fine for a list collection, but it not works while am working with DataTable.
Any idea on this?
–
PropertyInfo
is the reflection world, where types have explicit CLI properties. DataTable
does not belong to that world; it uses the System.ComponentModel
flexible property model, via TypeDescriptor
, PropertyDescriptor
, etc. Basically: there is no property in the CLI sense. PropertyDescriptor
can be used (and is used) to describe "properties" in a more flexible, dynamic sense, where the layout is not specified as a type, but is custom-defined, often on-the-fly at runtime.
So no: you can't do this. The question does not make sense; or at least, in the general case it doesn't. There is also "typed datasets", but frankly I strongly recommend staying far far away from them.
Incidentally, you can invent your own pseudo-properties for any type - there are extension points for this (TypeDescriptor
, ITypedList
, ICustomTypeDescriptor
, TypeConverter
, etc); but only code that explicitly uses System.ComponentModel
will ever see them.
–
–
DataView viewData = table.DefaultView;
Since a DataView implements ITypedList, you can get a collection of PropertyDescriptors from it:
(view as ITypedList).GetItemProperties(null)
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.