Binding to custom class object

G

Guest

I've used the Designer to create a strongly typed Dataset class from a stored
procedure definition. I called this class cMyDSraw, and the table within it
is called MyTable. The Designer generated nested class definitions for
cMyDSraw.MyTableDataTable and cMyDSraw.MyTableDataRow. Everything works fine
-- I can add a dataset of this class to a form and bind controls to the
fields, and they display the results of the sp call properly.

Now I want to derive from this class to provide some custom wrappers for
some of the database columns, by extending the definition of the base class's
nested class for the data row, e.g.:

public class cMyDS : cMyDSraw {

new public class MyTableDataRow : cMyDSraw.MyTableDataRow {

public bool MyBoolCol {
get { return (base.MyTextCol == @"Y"); }
set { base.MyTextCol = (value ? @"Y" : @"N"); }
}
}

The Designer can place an instance of this new derived DataSet class on my
form. However, the only properties available for design-time binding to
controls on the form are the ones in the "raw" class cMyDSraw.

Is this the correct approach? How can a make my "custom" columns such as
"MyBoolCol" visible in the binding dialogs in the Forms Designer?
 
G

Guest

I've realized my first attempt at deriving a new typed dataset class from the
designer-generated class was not done right. It would be necessary to expose
the typed table property in the derived class, so it could expose the new row
class definition. Something like the following:

public class cMyDS : cMyDSraw {

new public MyTableDataTable MyTable
{ get { return (MyTableDataTable) base.MyTable; } } // invalid cast!

new public class MyTableDataTable : cMyDSraw.MyTableDataTable
{
new public MyTableDataRow this[int index]
{ get { return ((MyTableDataRow )(this.Rows[index])); } }
}
// the rest as posted earlier
}

However, the attempt to cast the base table object as the derived type
fails, even though the derived class adds no columns. It looks like building
a completely new interface would be required.

Does anyone know of an example of deriving a new stongly typed dataset class
from one generated by the VS Dataset Designer, one that would make new
properties available for binding to controls on a form?
 

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