Casting to the Type of an object property?



Hi there,
I am wanting to write some generic code to add new rows to a
LookUpControl's LookUp DataSource. There is an event (ProcessNewVaule)
raised by the LookUpControl when a value is entered that is not in the
LookUpControl's LookUp DataSource that allows me to add the record at
that point.

Now I am using a Business Framework so each DataSets for the different
LookUpControl's LookUp DataSource's are of different Types.

eg;
// Type of Vendors DataSet is BusinessFramework.VendorDataSet
using BusinessFramework;
VendorDataSet VDS_Vendors = new VendorDataSet();

Now what I want to do is write a method that has two parameters:
LookUpEdit LUE_LookUpControl, string STR_RecordValue

Then write some generic code to add the new record in that method and
call it from the ProcessNewVaule event of the LookUpControl. Something
that can get the Type of the DataSet by interrogating the
LUE_LookUpControl LookUpControl and geting the DataSet that is assigned
to the LUE_LookUpControl.Properties.DataSource properties type and then
casting an object to that.
Somthing like this, except I can't use System.Data.DataSet as the cast
because it is not the right type. I need to find the type of the
DataSet assigned to the LUE_LookUpControl.Properties.DataSource and
cast to that. So how do I get the type and then substitute it for both
places you see "System.Data.DataSet" below?

System.Data.DataSet DS_LookUpDataSet =
(System.Data.DataSet)LUE_LookUpControl.Properties.DataSource;

DataRow DR_NewRow = DS_LookUpDataSet.Tables[0].NewRow();
DR_NewRow[1] = STR_RecordValue;
DS_LookUpDataSet.Tables[0].Rows.Add(DR_NewRow);
LUE_LookUpControl.EditValue = DR_NewRow[0];


Thank you for your time,

Scott.

.


Loading