Creating Browsable DataSource and DataMember properties

M

mzwilli

Hi, I'm trying to create browsable DataSource and DataMember
properties on a user control.

The idea is to create a descendent object, place a dataset then
specify the DataSource (DataSet) and DataMember (DataTable) by
browsing the controls properties.

I am close, but somtimes get an error when bad values get put into the
DataMember property.

Pretty sure I'm missing something. Can anybody help? Thanks!

Here's what I have so far:
/// <summary>
/// The DataSet used as the Master row set.
/// </summary>
[Browsable(true)]
[Category("Data")]
[Description("The DataSet used for this Child row set.")]
public System.Data.DataSet DataSource
{
get
{
return _DataSource;
}
set
{
_DataSource = value;
}
}

/// <summary>
/// The Table in the DataSet used for this Child row set.
/// </summary>
[Browsable(true)]
[Category("Data")]
[Description("The Table in the DataSet used for this Child row
set.")]
public System.Data.DataTable DataMember
{
get
{
return _DataMember;
}
set
{
_DataMember = value;
}
}
 
N

Nicholas Paldino [.NET/C# MVP]

Well, you shouldn't be typing the DataSource property as a DataSet and
the DataMember property as a DataTable, as databinding only requires that
the data source implement IList.

You should check the DataSource and DataMember properties on other
data-bound controls through Reflector, and take note of the attributes
applied to those. If you copy them, they will enable design-time support
for setting the data source and data member through the designer.
 

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