views:

194

answers:

3

I'm working on an application that presents the user with varied data, depending on the object being viewed. The objects are all of the same interface just with extended properties beyond once distinguished.

I'm looking for the "best" way to display a type-dependent control to the user. I would like to use tabs but I'm stuck with .NET 2.0 and from what I can gather the only way to hide/show tabs are to remove them and re-add them. That might be the best way but that leads to issues regarding blinking of the GUI components, keeping tabs on the active tab when reloading, etc.

I could make custom controls for each and either have them all loaded and hide/show when necessary (which I have done in the past on projects), or dispose and re-instantiate them...

To clarify best, I would say the closest balance between code elegance and program efficiency.

A: 

I have used and have had the best luck with loading them all and then showing/hiding the ones needed.

Disposing and re-instantiating everything always made things very messy.

In order to not have load time be horrible, you can instantiate them on first use. Something like:

IView LoadView(Type dependantType)
{
  // get the view or create one
  IView view = GetView(dependantType);
  if (view == null)
  {
    view = InstantiateViewAndAddToForm(dependantType);
    AddView(view);
  }

  //
  // do some binding to your model or whatever here
  //

  // make the correct view visible
  foreach (IView v in Views)
    view.Visible = v == view;
}
Alan Jackson
A: 

Could you just create a panel for each object and have a dictionary associate the object type and the panel?

You could just tell the panel to bring to front if they are all the same size, or set all Panels.Visible to be false, and just set the one you need to be true.

Fry
A: 

I have used DockPanel Suite for applications that require multiple tabs. It is an open source project, so you can actually modify the code if you wish.

The Suite has many functions, however, if you can just use the Tabs.

Jon