Hello,
I have the following button that when pressed, generates a duplicate box of information.
The button contains the following code:
**********************************
form1.omtrform.staticpage2.Button2::click - (FormCalc, client)
form1.Row.instanceManager.addInstance(1);
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
I then created a "remove" button with the following code.
****************************************
form1.Row.instanceManager.removeInstance(1);
******************************************
The problem with this remove button is that it removes the first box of info that you added. I would like to change this "remove" button to remove the last item that has been added to the form.
Thanks,
-Vargs
When using addInstance the parameter "1" refers to true. This means that the new instance is merged with the data model.
However when using removeInstance, the parameter refers to the instance that you want to remove. The instances use a zero-numbering system, so the first instance is Row[0], then Row[1], Row[2], etc.
The easiest way is to have the remove button in the row, so that the script in the click event can refer to the rows instance.
form1.Row.instanceManager.removeInstance(this.parent.index);
There is an example here: http://www.assuredynamics.com/index.php/category/portfolio/building-dynamic-tables/
In the example you want to have a look at Table 5 (using tables) or Table 6 (using subforms).
If the button is external to the row, then you can still script the button to remove the last instance. In this case you first need to count the number of instances and then delete the last instance.
// count the number of instances
// subtract 1 to get back to a zero-numbered basis
var nRows = form1.Row.instanceManager.count - 1;
form1.Row.instanceManager.removeInstance(nRows);
The above script would go in the click event of a button outside of the repeating object (row).
Hope this helps,
Niall
Assure Dynamics