Focal Point
Maintain Grid Control functionality questions

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8991061912

March 20, 2007, 01:36 PM
Ron R
Maintain Grid Control functionality questions
I’m just starting to work with the maintain grid control and was wondering if you could accomplish a couple of different tasks with the control.

We would like to bring up a set of data in a grid and allow the user to be able to change one value in row/column and then be able to copy and paste this change to all other rows in the grid. We are trying to make it easy for the user to change multiple values in a grid, similar to what you can do in Excel .

We would like to bring up a set of data and change individual fields in the grid and then when the user hits the update button, update the modified fields and update an audit field in the table with the datetime of the change, but only for those rows in the grid that have data that has been modified. I know you can easily update all rows in the grid by using “For All Update…”. What I’m not sure about is if you can loop through the stack and determine if a row has been changed and then update a field if something in the row has been changed.

Thanks,
Ron
March 20, 2007, 02:01 PM
Alan B
Ron

The ability to copy and paste is limited to a single cell as far as I can remember.

To compare values you can have 2 stacks, one stack from the retrieval and then copy this for display, then compare the 2 stacks, field by field.

Otherwise create a new field in the stack and create a new control on the page with just this field in it, and hide it, use an onchange event on each field in the main control to update this field to a value in the row changed, that can be picked up when processing the page.

Hope that makes sense!


Alan.
WF 7.705/8.007
March 20, 2007, 04:45 PM
Lusheng
Ron,

If you manually paste data to all other rows, you have to do one at a time, by double clicking on the cell and paste it as mentioned by Alan. You can place a button on the form to apply your changes in one row to all other rows by clicking button, which you have event handler coded.

To answer your 2nd question, you make a copy of original stack, put your updated data in a different stack, then do value comparison. Another way is you may set up an array (just a flag) to record focindex in stack which the value has been changed. Then you compare the stack.focindex with the value in that array, if the values match, then you know the value changed.
March 21, 2007, 09:37 AM
Maintain Wizard
Ron
There is quite a bit you can do with the grid. You can use either Maintain code or JavaScript code to do this. It's helpful to use JavaScript as the form does not have to reload everytime. However, in order to change rows and columns, you will have to use Maintain.

If the user changes a row, you can use the following code to set an Update flag in the grid:

function OnGrid1_OnCellChanged ( long col, long row, string text) {
if (col !=3)
{
Form1.Grid1.GetCell(3,row);
Form1.Grid1.CellSetText("Y");
Form1.Grid1.SetCell(3,row);
Form1.Grid1.RedrawCell(3,row);
}
}

This says, when a cell is changed, as long as it's not column 3 (That's my flag column) put a Y in the flag column. Now, when the user presses update, you can copy the updated rows to a new stack to copy:

For all copy from DisplayStk into UpdateStk
Where UpdateFlag = 'Y'
For all Update fields from UpdateStk

As for copying the changes to the other rows, that's pretty straight forward. Say the user changes the value of Field2 in row 1, and you want to apply that change to every row in the grid. You would just use the following code when the user presses the Process button:

Compute i/i2=2; -* Start at row 2 since the new data is in row 1
Repeat STK.foccount -* Substitute the name of your stack here
Compute stk(i).field2 = stk(1).field2;
Compute i=i+1;
endrepeat

Now, when the form redisplays, the value in field2 for all of the rows is the same as the entered value in row 1. This could probably be done in JavaScript as well.

Mark
March 22, 2007, 03:13 PM
Ron R
Thanks for all of the ideas. I think these will give me a good start.

Ron