Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / UltraExpandableGroupBox and controls added at Run-Time

UltraExpandableGroupBox and controls added at Run-Time

New Discussion
Greg Meisner
Greg Meisner asked on Jul 25, 2019 2:24 PM

We’ve run into a bit of a problem today.

We have a need to create UltraExpandableGroupBoxes at run time and add WinForms controls to them.

We need to do this because we do not know at design time how many Group Boxes we’ll need.

In code, we create the Ultra Expandable Group Box, and add a the Ultra Expandable Group Box Panel to it. Further down in our code, we add Win Forms controls to the Panel.

Once our code completes, and we “see” the form, we see the Ultra Expandable Group Box but NONE of the embedded controls.

As a test, we’ve tried adding a .Show() call to every added control at run-time. (That made no difference)

Insuring the controls we created at run-time didn’t go out of scope. (That made no difference)

In the Debugger, verified the Panel control had all of our child controls (5 were in Group Box #1, 20 were in Group Box #2)

We’ve verified the Visible attribute is set to true for the child controls, the Panel AND the Group Box – all are set to true.

Because the application is a Legacy app, we have a mixture of Windows Generic Controls and Controls purchased from Control Vendors like Infragistics. We even tried removing all controls but a Generic Windows Control. (That made no difference)

Any Suggestions?

Robert

Sign In to post a reply

Replies

  • 0
    Michael DiFilippo
    Michael DiFilippo answered on Jul 23, 2019 1:50 PM

    Hello Greg, 

    How are you adding a panel to the group box? The proper way is to re-parent your external components to the Container property of the group.

    For more details please visit:
    https://www.infragistics.com/help/winforms/winexplorerbar-create-a-control-container-group

    • 0
      Greg Meisner
      Greg Meisner answered on Jul 23, 2019 7:32 PM

      Michael,

      The Ultra Expandable Group Box itself is being created at run-time.  My code looks like this: (Note, this is the code Visual Studio created in its designer…)

      UltraExpandableGroupBox grpBox_1 = new UltraExpandableGroupBox(); UltraExpandableGroupBoxPanel ultraExpandableGroupBoxPanel_1 = new UltraExpandableGroupBoxPanel();

      // // grpBox_1 // grpBox_1.Controls.Add(ultraExpandableGroupBoxPanel_1); grpBox_1.Dock = System.Windows.Forms.DockStyle.Top; grpBox_1.ExpandedSize = new System.Drawing.Size(1125, 50); grpBox_1.Location = new System.Drawing.Point(0, iGroupYLocation); grpBox_1.Margin = new System.Windows.Forms.Padding(10); grpBox_1.Name = strNewGroupName; grpBox_1.Size = new System.Drawing.Size(1125, 50); grpBox_1.TabIndex = 0; grpBox_1.Text = strNewGroupName; grpBox_1.Visible = true; grpBox_1.Expanded = false; // // ultraExpandableGroupBoxPanel1 // ultraExpandableGroupBoxPanel_1.Dock = System.Windows.Forms.DockStyle.Fill; ultraExpandableGroupBoxPanel_1.Location = new System.Drawing.Point(3, 20); ultraExpandableGroupBoxPanel_1.Name = strNewGroupName + “_ExpandableGroupBoxPanel1”; ultraExpandableGroupBoxPanel_1.Size = new System.Drawing.Size(1119, 27); ultraExpandableGroupBoxPanel_1.TabIndex = 0; ultraExpandableGroupBoxPanel_1.Visible = true;

      When it’s time to add my control, I’m simply:

      grpBox_1.Panel.Controls.Add(gp1_lblLastEditedDate1);

      As you can see, the Group Boxes are empty…

      Any ideas?

    • 0
      Greg Meisner
      Greg Meisner answered on Jul 23, 2019 7:54 PM

      Michael,

      I’m basically following the code located at https://www.infragistics.com/help/winforms/infragistics.win.misc~infragistics.win.misc.ultraexpandablegroupbox

      to understand how to add controls. One big difference from the example of yours and Mine is – I’ve created the Ultra Expandable Group Box at run-time.

      My code looks like:

      UltraExpandableGroupBox grpBox_1 = new UltraExpandableGroupBox(); UltraExpandableGroupBoxPanel ultraExpandableGroupBoxPanel_1 = new UltraExpandableGroupBoxPanel();// // grpBox_1 // grpBox_1.Controls.Add(ultraExpandableGroupBoxPanel_1); grpBox_1.Dock = System.Windows.Forms.DockStyle.Top; grpBox_1.ExpandedSize = new System.Drawing.Size(1125, 50); grpBox_1.Location = new System.Drawing.Point(0, iGroupYLocation); grpBox_1.Margin = new System.Windows.Forms.Padding(10); grpBox_1.Name = strNewGroupName; grpBox_1.Size = new System.Drawing.Size(1125, 50); grpBox_1.TabIndex = 0; grpBox_1.Text = strNewGroupName; grpBox_1.Visible = true; grpBox_1.Expanded = false; // // ultraExpandableGroupBoxPanel1 // ultraExpandableGroupBoxPanel_1.Dock = System.Windows.Forms.DockStyle.Fill; ultraExpandableGroupBoxPanel_1.Location = new System.Drawing.Point(3, 20); ultraExpandableGroupBoxPanel_1.Name = strNewGroupName + “_ExpandableGroupBoxPanel1”; ultraExpandableGroupBoxPanel_1.Size = new System.Drawing.Size(1119, 27); ultraExpandableGroupBoxPanel_1.TabIndex = 0; ultraExpandableGroupBoxPanel_1.Visible = true;

      and I add a simple text box to the Group Box with:

      // Build a TextBox TextBox txtBox = new TextBox { Name = “TestTextBox” }; txtBox.Font = new System.Drawing.Font(“Segoe UI”, 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); txtBox.Location = new System.Drawing.Point(20, iChildControlYPosition); txtBox.Name = “gp” + iGroupIndex + “_txtbox” + iChildIndex; txtBox.Size = new System.Drawing.Size(68, 22); txtBox.TabIndex = 1; txtBox.Text = “Testing text”; txtBox.Visible = true;

      grpBox_1.Panel.Controls.Add(txtBox);

      Here is a pic of the output:

      Notice the empty panel? No Text Boxes are displayed!

      Any ideas?

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jul 23, 2019 8:15 PM

        Are you creating the ultraExpandableGroupBoxPanel1 in your code? If so, that's the problem. 

        The way UltraExpandableGroupBox works is that it creates and manages an inner panel that contains the controls you add. This inner panel is created automatically. If you are creating another panel and adding it in to your UltraExpandableGroupBox control, then there will be two different panels, one on top of the other, and the one you added will either be covered up or will cover the inner panel. 

        If you want to create an UltraExpandableGroupBox at run-time, you do not need to create the inner panel – it will already be created for you.

        This code works for me:

        var expandableGroupBox = new UltraExpandableGroupBox();
        this.Controls.Add(expandableGroupBox);
        
        var button = new Button();
        expandableGroupBox.Panel.Controls.Add(button);

      • 0
        Greg Meisner
        Greg Meisner answered on Jul 23, 2019 8:54 PM

        Mike,

        That doesn’t work for me at all….

        As a test, I simplified my code down to the bare essentials… In my app, I have a Panel that will hold the Ultra Expandable Group Box. At runtime, I create the Group Box just like you do, and add it to my panel with:

        this.panel4.Controls.Add(expandableGroupBox);

        I followed your code and added a button to the Group Box.

        Here’s what I see:  

        As a test, I added an Expandable Group Box to my form via the Visual Studio Designer. At run time, I placed the same button I used from your example into that control.

        So a Design Time control is able to accept controls added at run-time, but an Ultra Expandable Group box added at run-time never displays any controls. This is very confusing!

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jul 24, 2019 1:13 PM

        Using the designer code as a model for what to do at run-time will be confusing, because these are very different things. The designer has to serialize the inner panel, but you don’t need to do that at run-time.

        This really shouldn’t be complicated. The only tricky part of the whole thing is that you have to add your controls to the inner panel instead of to the UltraExpandableGroupBox directly. If it’s not working, then something else must be going wrong here.

        You didn’t include your code that adds the button to the inner panel, so it’s hard for me to see what’s wrong, but some things you might want to check are…

        Perhaps the button is not visible? You should try setting Visible to true just to make sure.

        Or perhaps it’s positioned out of view. So try calling SetBounds to make sure it’s at a value size and position.

        Are you sure your code is referencing the correct Panel and also the correct UltraExpandableGroupBox?

        I am attaching my sample project here, which I have updated to use a Panel so that it more closely matches your situation. So that way you can run my sample and verify that it works for you, which will eliminate the possibility that there is a bug or some other issue in the version of the controls you are using.

      • 0
        Greg Meisner
        Greg Meisner answered on Jul 24, 2019 3:15 PM

        Mike,

        After taking your test application and modifying it so that it starts to replicate what we are doing, I think I've discovered the source of the problem and why the controls are not visible.

        If I add a control to the Group Box with a Location beyond the ExpandedSize of the control, even if I grow the Expanded Size of the Group Box AFTER I add my control, the control is not visible. If I increment the ExpandedSize of the Group Box BEFORE I add my control, everything works as expected.

        Let me clean up the test code and I'll post it here for your reference.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jul 24, 2019 6:36 PM

        Does the control you are adding to the Panel have it's Anchor property set to include Bottom or Right? If so, then resizing the Panel after you added it would continue to position it out of view. That would explain that behavior. 

      • 0
        Greg Meisner
        Greg Meisner answered on Jul 24, 2019 8:57 PM

        Mike,

        I just looked at the form… All fields are defaulting to Top, Left.

        Here is the code that’s failing:

         

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jul 25, 2019 2:24 PM

        Hi Greg, 

        I took a look at your sample. I had some trouble getting it to run because you left out some important files like the resx file that was under the Properties folder. But I got around that and I was able to see that your second button is not visible.

        But this does not appear to have anything to do with setting the ExpandedSize before or after you add the button. It's simply an minor error in your code. You are not updating iChildYPosition after you add the first button. So the first and second buttons are both at the same location and they are overlapping. 
        So I was able to fix the problem your sample by simply adding these two lines of code: 

        AddOurControls(ref gbNumber1, "Button_1", iChildYPosition, 1, iChildIndex);
        iChildYPosition += 25;
        iChildIndex++;

        Completely aside from that, the ExpandedSize property is hidden from intellisense and isn't intended to be used in your code. It really only exists for the purposes of serialization and deserialization. This is yet another case where looking at the designer-generated code is leading you astray. Having said that, what you are doing here seems to be working fine. But I wouldn't recommend using that if you can avoid it.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Greg Meisner
Favorites
0
Replies
10
Created On
Jul 25, 2019
Last Post
6 years, 7 months ago

Suggested Discussions

Tags

No tags

Created by

Created on

Jul 25, 2019 2:24 PM

Last activity on

Feb 12, 2026 1:04 PM