Is it possible to use typed fields from a DataViewRow object?

J

Johann Blake

When adding a new row to a DataView, is it possible to cast the
returned DataViewRow to a typed row? Without casting, I am forced to
indicate the names of fields as strings when setting their values.
Example:

DataRowView drv = myDataset.SomeTable.DefaultView.AddNew();
drv["ID"] = Guid.NewGuid();
drv.EndEdit();

Since I already have a typed Dataset, it would be nice if there was a
way to do something like...

drv.ID = Guid.NewGuid();

This has the advantage that it is checked during compile time. Without
doing it this way, if I ever change a field's name or even delete it, I
won't know it until run-time.

Thanks for any help
Johann Blake
 
D

Dmytro Lapshyn [MVP]

Hi Johann,

A DataRowView should hold a reference to a DataRow which you can downcast to
the typed data row.

For example:

((MyTypedDataSet.MyTypedRow)theRowView.Row).ID = Guid.NewGuid();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top