Howto create tabpages dynamically?

  • Thread starter Thread starter Rainer Queck
  • Start date Start date
R

Rainer Queck

Hi NG,

I am looking for a good way to dynamically generate a bunch of TabPages.

I have a list of more or less identical object. For each of these objects I
need a user interface. My thought is, to provide a TabPage for every object
with controls on it to interact with them. How can that be achieved
dynamically.

The only way I can think of to do this is to prepare the max needed TabPages
and keep them in a list. But this would mean a lot of manual work. I am sure
there is a better way to do this. Is it possible to just define one TabPage
with the form designer and then inherit from it?

Thanks for hints and suggestions.

Rainer
 
I have read several posts regarding the difficulties of populating a
TabControl with objects that inherit from TabPage. It can probably be
done, but all I've read about are problems.

There is another approach: you could create a factory method for each
TabPage layout. Pass the object you want to show on the UI, choose the
correct factory method based on the object, and the factory returns you
a TabPage all ready to go, as it were.

Then you just have to add the TabPage to the TabControl's page
collection and it should appear to the user.
 
Hi Bruce,

thanks for your reply.
There is another approach: you could create a factory method for each
TabPage layout. Pass the object you want to show on the UI, choose the
correct factory method based on the object, and the factory returns you
a TabPage all ready to go, as it were.

Then you just have to add the TabPage to the TabControl's page
collection and it should appear to the user.
This sounds like a good idea, but still means quite a bit of work. (I am a
lazzy person you must know ;-)
Following this sugestion, means I would have to create each control on the
TabPage at run time, do the right possitioning and then bind the controls to
the objects properties (how can I do this?) .

Is there a way to do a deep copy of a tabpage? This way I could design one
as a "master TabPage". Then the factory method could copy the controls for
the new TabPage from the master....

Regards
Rainer
 
Hi,

Rainer Queck said:
Hi Bruce,

thanks for your reply.

This sounds like a good idea, but still means quite a bit of work. (I am a
lazzy person you must know ;-)

It's not that difficult, you said your objects were kind of similar , if so
you can have a predefined factory method that returns a tabpage with these
common fields (you can cut & paste it from the designer's generated code)
then the correct method factory fill up the rest of the controls, most
probably you have a small finite number of objets you want to handle this
way so you can define the code manually.
Is there a way to do a deep copy of a tabpage? This way I could design one
as a "master TabPage". Then the factory method could copy the controls for
the new TabPage from the master....

IMO this will be more complex to build and more slow to run
 
Hi Ignacio,
It's not that difficult, you said your objects were kind of similar , if
so you can have a predefined factory method that returns a tabpage with
these common fields (you can cut & paste it from the designer's generated
code) then the correct method factory fill up the rest of the controls,
most probably you have a small finite number of objets you want to handle
this way so you can define the code manually.
I was already putting this way in considerations. For the moment I found a
easier (not that beautiful but operatable) way.
- create TabPage
- create PropertyGrid
- add PropertyGrid (Fill) to TabPage
- add TabPage to TabControl.
As I said, not that beautiful, but it works for the moment. Through the
property grid I can now work on my objects ;-)

Regards
Rainer
 
Back
Top