How can I iterate through form controls

I have a common function that I would like to apply to every EpiCombo box on my form - preferably just on one sheet or just custom EpiCombos. Whatever is easier. How can I write that into a EpiViewNotification event?

Something like:

foreach (var eachEpiCombo in SerialNumberForm.OnlyEpiCombos)
{
  specialfunction(eachEpiCombo);
}

Try reading through this to see if it sparks any thoughts

Iterating Through Panels (Sheets) To Find Specifically Named Control - ERP 10 - Epicor User Help Forum (epiusers.help)

depending on how many controls you’re talking about and how dynamic the form is, you might also consider just referencing each control manually.

That post was definitely helpful, but I could not get my function to execute. I think it might be working, it’s probably something in the way I am calling my function. See anything obvious? I’m slightly beyond my comfort zone here… haha

	private void edvUD38View_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		// ** Argument Properties and Uses **
		// view.dataView[args.Row]["FieldName"]
		// args.Row, args.Column, args.Sender, args.NotifyType
		// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
		if ((args.NotifyType == EpiTransaction.NotifyType.Initialize))
		{
			if ((args.Row > -1))
			{
				foreach(Control c in SerialNumberForm.Controls)
				{
					if (c.Name.StartsWith("Vcmb"))
					{
						removeListItemsUnavailable(c);
					}
				}
			}
		}
	}
private void removeListItemsUnavailable(Control c)
	{
		// ** Place Event Handling Code Here **
		EpiCombo cmbBox = (EpiCombo) c;
		DataTable sourceTable = (cmbBox.DataSource as DataTable);
		var rows = sourceTable.Rows;
		DateTime rdisDate = (DateTime) edvUD38View.dataView[edvUD38View.Row]["Date03"];
		int rowCount = rows.Count;

		if (rowCount > 0) 
		{				
			for (var i = rowCount - 1; i >= 0; i--)
			{
				DataRow row = sourceTable.Rows[i];
				DateTime createDate = Convert.ToDateTime(row["CreateDate"]);
				if (createDate > rdisDate)
				{
					row.Delete();
				}
			}
			sourceTable.AcceptChanges();
		}
	}

I think what you’re trying to do is to modify the dataview, not the control itself.
I think your first question was answered, which was how to iterate through form controls.
The second question is more domain specific, but what are you trying to do exactly? Perhaps there is a simpler way.

I agree. You answered my question. I did move on to a different one. I am using UserCodes to populate these drop downs but I want to limit the items in the list to only items whose CreateDate is earlier than another date on my dataview. I couldn’t do it with a filter (I think because the filters only work with strings).

You should be able to add the CreatedDate column to the ComboBox and then use a regular filter / filter params to do the filtering server side.

1 Like

I tried doing that… but I must not be entering the right syntax. I thought it was because it was a string array in the filter. But by all means straighten me out. I tried something like:

CreateDate < '2022-03-01'

and even that didn’t work for me.

Side note: I did get the function to work. I think the EpiViewNotification was not the correct place to iterate through the controls.

1 Like

Try this setup

Works like a dream
FilterByDate

3 Likes

There are very very few I can count them with a single hand reasons why in an Epicor customization you should ever iterate over controls. The architecture of Epicor is such that each control is bound to a data view / data set and anything you need to do should be done to the data and not the control directly. Even the style of the control can be affected by the dataview properties.

Not saying it can’t be done this way, but it shouldn’t unless you have no other choice.

3 Likes

This is exactly the logic I thought should work… but I can’t get it to work. Just to be sure, after TransDate there is a comma and two apostrophes before the other bracket?
Maybe I’m losing my mind.
image

The RDIS Date is bound to UD38View.Date03.
Here I am looking at the Columns.
image

Here I am looking at the FiltersAppend

Yeah

CreateDate<='?[TransDate,'']'
1 Like

That’s why I resorted to trying to iterate through the controls… Because it seemed better than making a BeforeDropDown event for 27 EpiCombos… lol. All because I can’t get this filter to work like it evidently works. Perhaps it’s a 10.2.300 bug?

Do you get an error? Do a Trace / Changes only you should see the query in there.

Are the combos bound to UD38 also? I think the filter uses the field name and looks for the value in the same view, so if they are different views it might not work.

I don’t remember if you could use multi view columns in the filter, maybe, I can look later and see if I find any examples.

1 Like

I don’t get an error. When I did the trace, I did not find any reference to UserCodes like you have shown. I’m sure that must be part of my problem.

The combos are all bound to UD38.

Can you send screenshot of your whole properties panel for the combo. Do you have retrieve on activate turned on?

1 Like


image

Here, I expanded a few of the other fields so you can see what I have in them.