Iterating Through Panels (Sheets) To Find Specifically Named Control

After posting the previous novel concerning the solution I worked on, I went back to take a better look at Daryl Hewison’s suggestion and it appears that I missed a pretty obvious line in his code that enables further iteration through child controls contained within the parent:

else if (c.HasChildren)

That’s pretty important - because it completely negates all of the nonsense I posted above, but it also helps me understand how Daryl was automating the process of iterating through to the next level of controls without knowing anything about the controls themselves.

Using Daryl’s example, I came up with this code block, which eliminates the need to know the names of any of your form module controls, especially level by level –

Again, on form load, I declare/define the form by GUID:

Erp.UI.App.NonConfEntry.NonConfForm frmNonConf;
frmNonConf = (Erp.UI.App.NonConfEntry.NonConfForm)csm.GetNativeControlReference("<PLACE YOUR GUID HERE>");

I then define the control name parameter that I want to search on (in my case, the checkbox control and its label control end with the phrase “RequestMove”):

string strCtrlName = "RequestMove";

I then make the call to the method that performs the work by passing in the form object (as the parent control) and the control search string:

modifyCheckbox(frmNonConf, strCtrlName);

The method looks like this:

private void modifyCheckbox(Control parentControl, string strControlName)
{
	foreach (Control ctrl in parentControl.Controls)
	{
		if (ctrl.Name.EndsWith(strControlName))
		{
			ctrl.Visible = false;
		}
		else if (ctrl.HasChildren)
		{
			modifyCheckbox(ctrl, strControlName);
		}
	}
}

Tested and working, simply by editing the “Visible” property value in code and nothing else:


Thanks, Daryl… now I understand it!

1 Like