Is there a way to clone a panel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 2 forms. The 1st form dynamically creates controls into a panel, and
fills comboboxes from SQL statements. What I would like to do is copy that
panel to a second form? I could run the same function that I use to create
the panel on Form1, however I don't want to hit the database again to fill
the combobox. Is there a way to make a duplicate of this panel for use on
another form???
 
The best way to approach that problem would probably be to define an
interface for fetching the Panel's data:

interface IPanelDataProvider
{
GetPanelData()
}

.... then tell your panel to fill itself using the interface:

IPanelDataProvider panelDataProvider;
....
myPanel.FillWithData( panelDataProvider )

For the first panel, you would give it a class that implemented the
IPanelDataProvider interface and pulled the data straight from your
database using SQL.

For the second panel, you could have the 1st panel also implement the
IPanelDataProvider interface, but instead of pulling the data from the
database, it would just pull it from the values already stored in its
controls:

IPanelDataProvider provider;
Panel myPanel1, myPanel2;
....
provider = new MySQLDataProvider();
myPanel1.FillWithData( provider );
....
provider = myPanel1;
myPanel2.FillWithData( provider );
 
Back
Top