Configurator Array Woes

The following works well in the VS C# debugger. Can anyone suggest the changes needed to run in the E10 Configurator?:sleepy:

        string[] values = new string[] { "Text1", "Text2" };
        TextBox[] textBoxes = new TextBox[] { chr_X1, chr_X2 };

        for (int i = 0; i<values.Length; i++)
        {
            textBoxes[i].Text = values[i];
        }

What kind of error are you getting?

“The name ‘chr_X1’ does not exist in the current context”
“The name ‘chr_X2’ does not exist in the current context”

I have textboxes created that are named accordingly.

Don’t you need to put Inputs in front of the control name? e.g Inputs.chr_X1

    string[] values = new string[] { "Text1", "Text2" };
    TextBox[] textBoxes = new TextBox[] { Inputs.chr_X1, Inputs.chr_X2 };

    for (int i = 0; i<values.Length; i++)
    {
        textBoxes[i].Text = values[i];
    }

//Gets me the following error

Cannot implicitly convert type ‘Erp.Shared.Lib.Configurator.InputControlValueBound<Ice.Lib.Framework.EpiTextBox,string>’ to ‘System.Windows.Forms.TextBox’

Yep, that is because they don’t use the standard windows forms controls. If you change your array type to match the input type, and then use textBoxes[i].Value it would work I think.

I am assuming you are trying to move a set of fields into an array so that you can manage them
 here is a sample set of code to do this. Each variable type needs a separate array/list


var Width = new List<Erp.Shared.Lib.Configurator.InputControlValueBound<Ice.Lib.Framework.EpiNumericEditor, System.Decimal>>();
	Width.Add(Inputs.Width01_Dec);
	Width.Add(Inputs.Width02_Dec);
	Width.Add(Inputs.Width03_Dec);
	Width.Add(Inputs.Width04_Dec);
	Width.Add(Inputs.Width05_Dec);
	Width.Add(Inputs.Width06_Dec);
	Width.Add(Inputs.Width07_Dec);
	Width.Add(Inputs.Width08_Dec);
	Width.Add(Inputs.Width09_Dec);
	Width.Add(Inputs.Width10_Dec);
	Width.Add(Inputs.Width11_Dec);
	Width.Add(Inputs.Width12_Dec);
	Width.Add(Inputs.Width13_Dec);
	Width.Add(Inputs.Width14_Dec);
	Width.Add(Inputs.Width15_Dec);

var Painted = new List<Erp.Shared.Lib.Configurator.InputControlValueBound<Ice.Lib.Framework.EpiCheckBox, System.Boolean>>();
	Painted.Add(Inputs.Painted01_Chk);
	Painted.Add(Inputs.Painted02_Chk);
	Painted.Add(Inputs.Painted03_Chk);
	Painted.Add(Inputs.Painted04_Chk);
	Painted.Add(Inputs.Painted05_Chk);
	Painted.Add(Inputs.Painted06_Chk);
	Painted.Add(Inputs.Painted07_Chk);
	Painted.Add(Inputs.Painted08_Chk);
	Painted.Add(Inputs.Painted09_Chk);
	Painted.Add(Inputs.Painted10_Chk);
	Painted.Add(Inputs.Painted11_Chk);
	Painted.Add(Inputs.Painted12_Chk);
	Painted.Add(Inputs.Painted13_Chk);
	Painted.Add(Inputs.Painted14_Chk);
	Painted.Add(Inputs.Painted15_Chk);

var LineDesc = new List<Erp.Shared.Lib.Configurator.InputControlValueBound<Ice.Lib.Framework.EpiTextBox, System.String>>();
	LineDesc.Add(Inputs.LineDesc01_Chk);
	LineDesc.Add(Inputs.LineDesc02_Chk);
	LineDesc.Add(Inputs.LineDesc03_Chk);
	LineDesc.Add(Inputs.LineDesc04_Chk);
	LineDesc.Add(Inputs.LineDesc05_Chk);
	LineDesc.Add(Inputs.LineDesc06_Chk);
	LineDesc.Add(Inputs.LineDesc07_Chk);
	LineDesc.Add(Inputs.LineDesc08_Chk);
	LineDesc.Add(Inputs.LineDesc09_Chk);
	LineDesc.Add(Inputs.LineDesc10_Chk);
	LineDesc.Add(Inputs.LineDesc11_Chk);
	LineDesc.Add(Inputs.LineDesc12_Chk);
	LineDesc.Add(Inputs.LineDesc13_Chk);
	LineDesc.Add(Inputs.LineDesc14_Chk);
	LineDesc.Add(Inputs.LineDesc15_Chk);

	//This will set all the fields to a specific value
	for (j = 0; j < 15; j++)
	{
		
		Painted[j].Value = true;
		Width[j].Value = 10;
		LineDesc[j].Value = "A Desc";

	}	

	//This will make all the fields invisible
	for (j = 0; j < 15; j++)
	{
		
		Painted[j].Invisible = true;
		Width[j].Invisible = true;
		LineDesc[j].Invisible = true;

	}	
1 Like

You can also use something like this. You can change the Inputs.epiPcTextBox1.Control.Parent.Controls to something else, such as a group collection, and also change the if condition to perhaps filter by contains on control name or what have you.

foreach(Control ctrl in Inputs.epiPcTextBox1.Control.Parent.Controls) {
			if (ctrl is Ice.Lib.Framework.EpiTextBox) {
				((InputControlValueBound<Ice.Lib.Framework.EpiTextBox, String>)Inputs[ctrl.Name].Value).Value = "My Value"; 
			}
}
3 Likes

Very cool @danbedwards
 - a new trick to include in my bag of tricks.
I have extended what you provided
 The following code will clear ALL normal inputs (Text inputs, Radio sets, Combos, Images, Browsers)
 EDIT: This NOW INCLUDES resetting of Date fields to Null

/*This will Clear ALL Fields in the configurator, resetting to a blank/null state
*/


foreach(Control ctrl in Inputs.epiPcTextBox1.Control.Parent.Controls) 
{
	if (ctrl is Ice.Lib.Framework.EpiTextBox)				
		((InputControlValueBound<Ice.Lib.Framework.EpiTextBox, String>)Inputs[ctrl.Name].Value).Value = ""; 

	if (ctrl is Ice.Lib.Framework.EpiNumericEditor)
		((InputControlValueBound<Ice.Lib.Framework.EpiNumericEditor, Decimal>)Inputs[ctrl.Name].Value).Value = 0; 

	if (ctrl is Ice.Lib.Framework.EpiCheckBox)
		((InputControlValueBound<Ice.Lib.Framework.EpiCheckBox, bool>)Inputs[ctrl.Name].Value).Value = false; 

	if (ctrl is Erp.Lib.Configurator.PcControls.EpiRadioSet)
		((InputControlValueBound<Erp.Lib.Configurator.PcControls.EpiRadioSet, String>)Inputs[ctrl.Name].Value).Value = ""; 

	if (ctrl is Erp.Lib.Configurator.PcControls.EpiPcPictureBox)
		((InputControlValueBound<Erp.Lib.Configurator.PcControls.EpiPcPictureBox, String>)Inputs[ctrl.Name].Value).Value = ""; 

	if (ctrl is Ice.Lib.Framework.EpiUltraCombo)
		((InputControlValueBound<Ice.Lib.Framework.EpiUltraCombo, String>)Inputs[ctrl.Name].Value).Value = ""; 

	if (ctrl is Erp.Lib.Configurator.PcControls.EpiPcBrowser)
		((InputControlValueBound<Erp.Lib.Configurator.PcControls.EpiPcBrowser, String>)Inputs[ctrl.Name].Value).Value = ""; 

	if (ctrl is Ice.Lib.Framework.EpiDateTimeEditor)
		((InputControlValueBound<Ice.Lib.Framework.EpiDateTimeEditor, DateTime?>)Inputs[ctrl.Name].Value).Value = null; 
}
1 Like

I use something just like that – just wanted to mention it has caused me a lot of headaches too as it will run all of the input changed events. So many null reference errors and invalid input errors. :rage:

What a great resource here. Thank you all for sharing. The better explanation (I suppose I should have provided to begin with) follows. I am actually trying to accomplish the opposite. I am parsing content from a textbox to an array. That array is already used in other logic. Proper sequencing of the array content, redundancy checking, etc
 I hoped to find the short code version of what follows to populate textboxes on a form.

	for (int i = 1;i<=iNumOfXvariations;i++)
	{
		if (iNumOfXvariations == 6)
			{	
			Inputs.chr_X1.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[1]);
			Inputs.txt_XVar_1_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[1]);
			Inputs.chr_X2.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[2]);
			Inputs.txt_XVar_2_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[2]);
			Inputs.chr_X3.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[3]);
			Inputs.txt_XVar_3_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[3]);
			Inputs.chr_X4.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[4]);
			Inputs.txt_XVar_4_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[4]);
			Inputs.chr_X5.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[5]);
			Inputs.txt_XVar_5_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[5]);
			Inputs.chr_X6.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[6]);
			Inputs.txt_XVar_6_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[6]);
			}
			else	if (iNumOfXvariations == 5)
			{	
			Inputs.chr_X1.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[1]);
			Inputs.txt_XVar_1_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[1]);
			Inputs.chr_X2.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[2]);
			Inputs.txt_XVar_2_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[2]);
			Inputs.chr_X3.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[3]);
			Inputs.txt_XVar_3_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[3]);
			Inputs.chr_X4.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[4]);
			Inputs.txt_XVar_4_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[4]);
			Inputs.chr_X5.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[5]);
			Inputs.txt_XVar_5_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[5]);
			}
			else if (iNumOfXvariations == 4)
			{	
			Inputs.chr_X1.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[1]);
			Inputs.txt_XVar_1_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[1]);
			Inputs.chr_X2.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[2]);
			Inputs.txt_XVar_2_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[2]);
			Inputs.chr_X3.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[3]);
			Inputs.txt_XVar_3_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[3]);
			Inputs.chr_X4.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[4]);
			Inputs.txt_XVar_4_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[4]);

			}
			else if (iNumOfXvariations == 3)
			{	
			Inputs.chr_X1.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[1]);
			Inputs.txt_XVar_1_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[1]);
			Inputs.chr_X2.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[2]);
			Inputs.txt_XVar_2_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[2]);
			Inputs.chr_X3.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[3]);
			Inputs.txt_XVar_3_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[3]);

			}
			else if (iNumOfXvariations == 2)
			{	
			Inputs.chr_X1.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[1]);
			Inputs.txt_XVar_1_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[1]);
			Inputs.chr_X2.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[2]);
			Inputs.txt_XVar_2_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[2]);

			}
			else if (iNumOfXvariations == 1)
			{	
			Inputs.chr_X1.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[1]);
			Inputs.txt_XVar_1_Description.Value= PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[1]);
			}


}

I don’t know if you can avoid it - but PCLookups are horrifically slow - I try to replace with BAQ’s or hardcode the data into the code now if possible.

Something like this? Sloppy code, just to be used as an example, and it may have a typo or two

	for (int i = 1;i<=iNumOfXvariations;i++)
	{
		foreach (Control ctrl in Inputs.chr_X1.Control.Parent.Controls)
		{
			if (ctrl.Name.Contains("chr_X" + i.ToString()) // Would find chr_X1 on first pass
				{
					((InputControlValueBound<Ice.Lib.Framework.EpiTextBox, String>)Inputs[ctrl.Name].Value).Value = PCLookUp.DataLookup("1279_XVars_Lookup_Table", "XVariation", sX[i]);
				}
			if (ctrl.Name.Contains("txt_XVar_" + i.ToString()) // Would find txt_XVar_1_Description on first pass
				{
					((InputControlValueBound<Ice.Lib.Framework.EpiTextBox, String>)Inputs[ctrl.Name].Value).Value = PCLookUp.DataLookup("1279_XVars_Lookup_Table", "Description", sX[i]);
				}
		}
	}

Here is how to clear the EpiDateTimeEditor

DateTime? nullDateTime = null;
Inputs.epiPcDateTimeEditor1.Value = nullDateTime;
2 Likes

I do not understand how this works.

Every control has a parent (like an owner) with the root parent being the form.

Inputs.chr_X1.Control <- Gets the control for the input (I think it would be an EpiTextBox in this case)
Inputs.chr_X1.Control.Parent <- In this case the parent is the form
Inputs.chr_X1.Control.Parent.Controls <- The collection of controls owned by the form.

2 Likes

Tim,
Do you have any code to do the same thing with PictureBoxes?

I have, without success, tried to find out what base class the control uses EpiPictureBox works when declaring the list:


[quote="timshuwy, post:7, topic:45183"]
`List<Erp.Shared.Lib.Configurator.InputControlValueBound<Ice.Lib.Framework.EpiCheckBox, System.Boolean>>();`
[/quote]

List<Erp.Shared.Lib.Configurator.InputControlValueBound<Ice.Lib.Framework.EpiPictureBox, System.String>>();

.. but adding a pictureBox into the List fails. I have also investigated the Infragistics UltraPicturebox by looking in the Erp.Shared.Lib.Configurator dll in Visual studio as I use the Infragistics controls in other projects but it doesn't appear,

I’m trying to get this to work in a Configurator UD Method, and I keep getting a compile error, do I need to add a reference?

error CS0234: The type or namespace name ‘Framework’ does not exist in the namespace ‘Ice.Lib’ (are you missing an assembly reference?)