Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

Dynamically adding new panels

Last post 07-24-2008 12:20 by [Infragistics] Mike Dour. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 07-17-2008 3:17

    • vrn
    • Top 25 Contributor
    • Joined on 03-21-2008
    • Points 3,750

    Dynamically adding new panels

    Application has several panels some or all of which the user may choose to have on his screen. It is very much like Visual Studio in that user may choose their own combination of panels, their layout (docking) etc. He can choose which panel to keep closed. Each open panel has one user control filling it.

    When the application restarts, I want to restore the last settings i.e. the panel docking, the controls inside them. very much like Visual Studio

    I am wondering :

    1. how would the application know which panels were open last time and where they were placed by the user? So, panel x may have been docked to top by one user and while docked bottom by another use and a third user may have closed it completely. In other words, at app start time, I need to know which panels to open and where to dock them. I am hoping the DockManager would provide some help with that. Any samples code available? 

    2. once I determine the panel that are to be opened, I would then instantiate the control and add it to the panel? Is that the approach you would recommend. I know this is not an Infragistics question per se but I am hoping there is something in the toolset that I may be able to exploit.

     Thanks!

    • Post Points: 20
  • 07-17-2008 9:32 In reply to

    Re: Dynamically adding new panels

    vrn:
    1. how would the application know which panels were open last time and where they were placed by the user? So, panel x may have been docked to top by one user and while docked bottom by another use and a third user may have closed it completely. In other words, at app start time, I need to know which panels to open and where to dock them. I am hoping the DockManager would provide some help with that. Any samples code available? 
     

    The UltraDockManager has SaveAs... and LoadFrom... method which allow you to save and load layout files. This will do exactly what you ask in your first question. You would typically want to save the layout file in the FormClosed event and load it if it exists at the end of the constructor or in the Load event of the Form. The Docking Demo sample uses the layout files, but in a slightly different way. It allows you to save and load layout files from a menu. It also saves the layout when the program loads and allows the user to reset the layout by loading in the originally saved layout.

    vrn:
    2. once I determine the panel that are to be opened, I would then instantiate the control and add it to the panel? Is that the approach you would recommend. I know this is not an Infragistics question per se but I am hoping there is something in the toolset that I may be able to exploit.

    I haven't tried using it with loading layout files yet, but there is an InitializePane event which you could use to only load a control once the pane is first shown.

    • Post Points: 20
  • 07-17-2008 10:31 In reply to

    • vrn
    • Top 25 Contributor
    • Joined on 03-21-2008
    • Points 3,750

    Re: Dynamically adding new panels

    [Infragistics] Mike Dour:
    The UltraDockManager has SaveAs... and LoadFrom... method which allow you to save and load layout files. This will do exactly what you ask in your first question. You would typically want to save the layout file in the FormClosed event and load it if it exists at the end of the constructor or in the Load event of the Form. The Docking Demo sample uses the layout files, but in a slightly different way. It allows you to save and load layout files from a menu. It also saves the layout when the program loads and allows the user to reset the layout by loading in the originally saved layout.
     

    Thanks Mike! When you say "Docking Demo", is that on the Infragistics sample code installed with the toolkit or something on the website? If latter, can you provide link?

    [Infragistics] Mike Dour:
    I haven't tried using it with loading layout files yet, but there is an InitializePane event which you could use to only load a control once the pane is first shown.

    The requirement involves having to show a new panel for each user action and fill it with a user control. So, for say 15 user actions, I will need 15 different user controls. I have two choices

    1. Design 15 different panels and fill the control at InitializePanel time.

    2. Dynamically generate the panels and then fill it with the controls

    The advantage to the second approach is its scalability. If the application later needs to support 5  new user controls , none of the layout code needs to change.

     Do you think I can achieve #2 and still save the layout? So, one user may open User Control 1(UC1), UC10 and UC11 in three dynamically generated panels. While in another scenario it was UC2, UC4 in two dynamically generated panels. Since these controls are coming up in dynamically generated panel, what would the DockManager save for the two users? Would it know how many panels to be generated at initialization, where to dock those and which controls are to be placed on those panels?

    Thanks!

    • Post Points: 20
  • 07-18-2008 9:34 In reply to

    Re: Dynamically adding new panels

    vrn:
    Thanks Mike! When you say "Docking Demo", is that on the Infragistics sample code installed with the toolkit or something on the website? If latter, can you provide link?

    That is one of the installed samples. I'm not sure where it is located, but it might be located in the toolbars section.

    vrn:
    Do you think I can achieve #2 and still save the layout? So, one user may open User Control 1(UC1), UC10 and UC11 in three dynamically generated panels. While in another scenario it was UC2, UC4 in two dynamically generated panels. Since these controls are coming up in dynamically generated panel, what would the DockManager save for the two users? Would it know how many panels to be generated at initialization, where to dock those and which controls are to be placed on those panels?

    The dock manager would be able to do this if the controls were somewhere on the Form when the LoadFrom... method was called. When you load a layout file, the dock manager will initialize a DockableControlPane with the settings it was saved with. Then it will look at the controls on the form and try to find a control with the same Name property value as the control that was docked in the pane. If one is not found, the pane is removed. You will need to save another file with the layout file. This file will indicate to you which controls should be initialized and added to the form before loading the dock manager's layout file.

    • Post Points: 35
  • 07-21-2008 2:14 In reply to

    • vrn
    • Top 25 Contributor
    • Joined on 03-21-2008
    • Points 3,750

    Re: Dynamically adding new panels

    [Infragistics] Mike Dour:
    The dock manager would be able to do this if the controls were somewhere on the Form when the LoadFrom... method was called. When you load a layout file, the dock manager will initialize a DockableControlPane with the settings it was saved with.

    Mike, From what you are saying it seem the key is to make application know which controls were open when it last closed. That way, if the application instantiate those controls at LoadForm time, the dockmanage would do the needful to put it on the correct pane. Do you agree with conclusion?

     Second question, my entire application is developed as a user control. The dock manager is on the user control instead of the form. So what you said about "LoadForm" is applicable if the dockmanager is on the Form. What is event that I should be concerned about when dock manager is on the user control?

     Thanks!

    • Post Points: 20
  • 07-21-2008 9:18 In reply to

    Re: Dynamically adding new panels

    vrn:
    Mike, From what you are saying it seem the key is to make application know which controls were open when it last closed. That way, if the application instantiate those controls at LoadForm time, the dockmanage would do the needful to put it on the correct pane. Do you agree with conclusion?

    Yes, that is correct.

    vrn:
    Second question, my entire application is developed as a user control. The dock manager is on the user control instead of the form. So what you said about "LoadForm" is applicable if the dockmanager is on the Form. What is event that I should be concerned about when dock manager is on the user control?

    Yes, it will work with a user control as well. Also, I wasn't referring to anything called LoadForm, I was talking about the LoadFrom... methods. The dock manager has LoadFromXml and LoadFromBinary methods which load a layout file depending on what format it was saved in.

    • Post Points: 5
  • 07-22-2008 8:25 In reply to

    • vrn
    • Top 25 Contributor
    • Joined on 03-21-2008
    • Points 3,750

    Re: Dynamically adding new panels

    Thank for the help so far Mike. Your suggestions as well the Docking Demo you suggested helped me get a whole lot further.

    - Currently I have this simple code in my play app that generates a new control at runtime and TRIES to dock it as part of a existing tab group of right-docked controls. Instead of that becoming part of the tabgroup, the userControl3 just becomes a new panel docked right but sitting side-by-side to that tab group. How do I make it part of that tab group of right-docked controls?

    UserControl1 userControl3 = new UserControl1();

    ultraDockManager1.DockControls(new Control[1] { userControl3 }, Infragistics.Win.UltraWinDock.DockedLocation.DockedRight, Infragistics.Win.UltraWinDock.ChildPaneStyle.TabGroup);

    - I see code snippet on the forum where docking is done to a named dockarea i.e. referencing DockArea by its key. It seems like a great way to logically group controls but I do not know how to use it.

    • Post Points: 20
  • 07-22-2008 10:08 In reply to

    Re: Dynamically adding new panels

    Try using the following code:

    this.ultraDockManager1.BeginUpdate();

    bool paneAddedToGroup = false;

    foreach ( DockAreaPane dockArea in this.ultraDockManager1.DockAreas )
    {
     if ( dockArea.DockedLocation != DockedLocation.DockedRight )
      continue;

     DockableControlPane controlPane = this.ultraDockManager1.ControlPanes.Add( this.userControl3 );
     dockArea.Panes.Add( controlPane );
     paneAddedToGroup = true;
     break;
    }

    if ( paneAddedToGroup == false )
    {
     this.ultraDockManager1.DockControls(
      new Control[ { this.userControl3 },
      DockedLocation.DockedRight,
      ChildPaneStyle.TabGroup );
    }

    this.ultraDockManager1.EndUpdate();

    To use a named dock area, you can set the Key property of a dock area. Then when you access the DockAreas collection of the dock manager, you can specify that key instead of an index when trying to get a dock area from the collection.

    • Post Points: 20
  • 07-24-2008 0:08 In reply to

    • vrn
    • Top 25 Contributor
    • Joined on 03-21-2008
    • Points 3,750

    Re: Dynamically adding new panels

    - Once the user has closed a docked pane by clicking on the "x", how can I bring it back programmatically? I read somewhere that I have do a Show() on the pane. In my current design, I am dropping controls directly onto the form. How do I determine the pane I need to Show()?  

    - When  the pane is restored programmatically, would it recover the last docking when it was closed?

    - Related to the first question, to find out which panes are not visible i.e. ones which are closed using the "x". I am guessing I need to iterate over some collection and check some property. I would like to know what that collection and property is.

    Thanks!

    • Post Points: 35
  • 07-24-2008 1:32 In reply to

    • jct
    • Top 50 Contributor
    • Joined on 03-18-2008
    • Points 1,610

    Re: Dynamically adding new panels

    I did something like that. (maybe there is a built-in feature for that, anyone?)

    My idea was to populate a menu with all the control names that docked. When the user clicked on a menu item, I get the control name from it and send it to this method:

    public void ShowListControl(Form ContainerForm, UltraDockManager DockManager, string controlName)

    {

    Control control = ContainerForm.Controls.Find(controlName,
    true).FirstOrDefault();if (control != null)

    {

    var controlPane = DockManager.ControlPanes[control];

    if (controlPane != null)

    {

    controlPane.Show();

    controlPane.Activate();

    }

    }

    else // If the control is floating, it cannot be found via the form

    {

    foreach (var controlPane in DockManager.ControlPanes)

    {

    if (controlPane.Control != null && controlPane.Control.Name == controlName)

    {

    controlPane.Show();

    controlPane.Activate();

    break;

    }

    }

    }

    }

    • Post Points: 20
  • 07-24-2008 12:19 In reply to

    Re: Dynamically adding new panels

    vrn:
    Once the user has closed a docked pane by clicking on the "x", how can I bring it back programmatically? I read somewhere that I have do a Show() on the pane. In my current design, I am dropping controls directly onto the form. How do I determine the pane I need to Show()?  

    Yes, the Show() method will show the pane again. You can give each control pane a Key which will help you identify each pane. When you are looking for the pane, you can access the dock manager's ControlPanes collection and index into it with the key of the pane you are looking for.

    vrn:
    When  the pane is restored programmatically, would it recover the last docking when it was closed?

    Yes. The only exception to this is if the pane was unpinned and closed. When shown again, it would be pinned. This is how VS behaves and the dock manager duplicates this behavior.

    vrn:
    Related to the first question, to find out which panes are not visible i.e. ones which are closed using the "x". I am guessing I need to iterate over some collection and check some property. I would like to know what that collection and property is.

    You can iterate over the ControlPanes collection of the dock manager to get all panes which have controls you have docked (all panes which aren't groups or dock area). On these panes you can get the Closed property to determine whether it is hidden or not. You can also set the Closed property to False to show a pane, but if the pane's parent pane were also closed, the pane would not show, whereas calling Show() will show any hidden parent panes as well.

    • Post Points: 5
  • 07-24-2008 12:20 In reply to

    Re: Dynamically adding new panels

    jct, You can try to assign each control pane a key that is the name of the control it hosts. Then you can just index into the dock manager's ControlPanes collection with the control name.

     

    • Post Points: 5
Page 1 of 1 (12 items)
Powered by Community Server (Commercial Edition), by Telligent Systems