How to clear all controls on a custom sheet

I am creating a custom sheet in Quote Entry to enter data related to a particular piece of equipment that the product on the quote line is for. If for some reason, we want to change all of the info on that sheet, is there a way to clear out all controls on the sheet either by changing the primary choice or by using a button that will reset all of the fields on this sheet? I don’t want to delete the Quote Line, just remove all values that were selected on the new sheet. Thanks in advance for any help you may be able to provide.

Anyone?

You’d have to write the code on the form to run through the fields, but there is a Button in the toolbox for Form Customization.

Any details on what I’d need to run to clear them all? Would I be looking to run like a foreach and cycle through all of the controls on the sheet? If so, any ideas on the base setup for that? I’m only starting to scratch the surface with C# so I’m not too sure on how to get started with some of these types of things.

While that’s possible, it’s not trivial. It really depends on if you truly needs to be dynamic, for instance if you want to re-use the code elsewhere, or make sure it doesn’t break on changes. If it were me, I would simply list all of the controls that you have added and clear them from within the button click method. Once you have that working, you can look at making the coding smarter with getting the controls dynamically.

Basically, start simple, then add complexity.

1 Like

Go big or go home, Brandon. :stuck_out_tongue:

1 Like

Well, I probably have close to 100 controls that I need to clear and was hoping to not have to list them each out. I have done some coding before (probably about 10 years ago now), but just am not that familiar yet with C#. If someone has the basics of how I would try to get the controls from the page, I can probably work through the remainder of the code to make them all cleared.

I imagine you could do something like this: Epicor Insights 2019 Customization Tips Tricks and Troubleshooting Code - #3 by rbucek - ERP 10 - Epicor User Help Forum

private void btnClearFilters_Click(object sender, System.EventArgs args)
	{
        Ice.Lib.Framework.EpiBasePanel pnl = (Ice.Lib.Framework.EpiBasePanel)csm.GetNativeControlReference("9fc6a346-e062-4c54-a790-6e37882f4463");
        foreach (Control c in pnl.Controls)
        {
            if (c.GetType() == typeof(EpiTextBox))
                c.Text = string.Empty;
            if (c.GetType() == typeof(EpiNumericEditor))
            {
                ((EpiNumericEditor)c).Value = null;
            }
            if (c.GetType() == typeof(EpiCombo))
            {
                c.Text = string.Empty;
            }
            if (c.GetType() == typeof(EpiDateTimeEditor))
            {
                c.Text = string.Empty;
            }
            if (c.GetType() == typeof(EpiTimeEditor))
            {
                c.Text = string.Empty;
            }
        }				
	}
2 Likes

That looks to be exactly what I was hoping for! Thanks @hmwillett! I’ll be sure to update once I have a chance to test this out in my UI Customization.

Well, if you want to read through a long thread about almost the same thing, this one describes something similar to what you are looking for.

Thanks @Banderson! I’ll have to give that a read when I have a few minutes (not sure when that will be). Since I’m only referencing a specific tab, I think the post @hmwillett provided should do the trick for me. Thanks to you both!

Simplest is best when simplest works. Having seen others stumble slightly, I feel obliged to mention that controls within other controls, such as those in groupboxes, need extra layers of checks, but if you’ve laid your tab out simply with all the controls right at the tab level then @hmwillett 's code is just what you need.

Thank you for this! I do have my layout in Group Boxes, so I’ll need the extra step. Do you happen to have details on that or will the post by @Banderson cover this?

That post covers most things, if I remember rightly.

But in essence, the simple code does a foreach loop through the controls in a collection, which includes the groupboxes themselves. The controls within each groupbox are in that groupbox’s controls collection, so you need to loop through those independently.

If your control layout is manageable, you can just hard-code as many loops as you need for the top-level controls and each groupbox. If you want to make it so that it won’t need adjusting with future layout changes then you might find the time invested in reading the post @Banderson mentioned pays you back. You’re best equipped to judge what fits this particular case.

Thanks @dhewi!

You can just traverse the control tree and recursively clear your selection. Here is an example - not exactly a match but you will get the idea

void DoSomeOperation(DockPanel panel) {
   // Clear your selections
}

void IterateChildPanels(DockPanel parentPanel) {
   if(parentPanel == null) return;
   for(int i = 0; i < parentPanel.Count; i++) {
      DockPanel childPanel = parentPanel[i];
      if(childPanel.Count == 0)
         DoSomeOperation(childPanel);
      else 
         IterateChildPanels(childPanel);
   }
}
1 Like