Use a Dataset to store Property Information
Posted on 2011-09-16
I am working with a DataGridView control builder. This Builder allows a user to select a DataSource and customize the DataGridView. All of the settings would be saved to an XML file which can be called by one Function and re-displayed. I can quickly use this builder to create a library of DataGridViews in any of my applications and not have to wory about individually coding each DataGridView. This will make for MUCH faster application developement and display of data for my customers.
I store the data for the DataGridView in a DataSet. This makes it easy to poass all of the necessary settings. Creating the structure of the dataset is not my problem, nor is creating XML files. The issue I am having now is storing the information for the Public Properties in a DataTable and calling them back later.
Say I have a Table called "Properties". This table has three columns; 1) PropertyName, 2) PropertyVariable, and 3) PropertyValue.
1. PropertyName is the abbreviated name of the Public Property Setting. 2) PropertyVariable is the FULL Public Propery Variable. 3) ProperyValue is the actual value for the Public Property. I know I can use Reflection to iterate Public Properties, but to store, Set and Get the value is my major issue right now.
Using PropertyInfo (pInfo) I can loop through the Public Properties and get the Name of the Public Property. I store this name in column 2 (PropertyName). How do I Get the value of the Public Property to store in (PropertyValue)? And also do the reverse which is to Set the value once read from column 3? At this point I am using a loop (iLoop) and want to take the PropertyName, match it to the Public Propery and Set the value. Could you show me a sample of code for this?