Row and Column Totals in Callback Mode

TrueGrid Sample

Here's a small app demonstrating row and column totals in call back (Application) mode using TrueGrid Pro.

We'll start with three TrueGrid tables. You could just use one and a few Select Case statements for row and column, but I prefer to use three for readability and code segregation.

No data control? Correct - just make sure the .DataMode property is set to 1 - Application and set up table1 columns as editable. Set up table2 and table3 columns as not editable. For a table1 of 5 rows and 5 columns, we must have an array for data in each cell. I didn't like this at first as I felt TrueGrid should keep up with its own data. But trust me - you'll need this array! If you can figure out a way to do without it, please tell me. So :

Now we need to do some initialisation, and I prefer the form load event (Listing One). We first set up the rows and columns or we won't be able to enter data, and then we need to tell TrueGrid to keep up with column totals - a little tricky!

You could leave the background colour as white but I like the 3D look.

One other trick with column totals. On the ColumnSumChanged event, make sure you refresh the row, not the entire grid.

If you refresh the grid, the entire grid flashes, which doesn't look too good. In this case, we'll be updating table3 from the table1 ColumnSumChanged event.

Next we need to deal with fetching our data. The fetch event is fired for every cell but don't let this throw you. DataArray is handled in Update event. Value is current cell value of Row and Column :

On the other side of the fetch coin is, of course, update. Once our user has finished typing in a value in one of the cells on grid we need to save the value - that's what DataArray is for:

Now we need to make sure our row sums (in table2) are correct. Be careful here - this is the trickiest event as it uses another cool TrueGrid property - referencerow. Setting it does not affect .rowindex or .columnindex. So we step through each cell using a loop. Referencerow tells us what row to use, ColumnText (column) tells us what column.

I hide the zero values, because I like the look. Refer to code below:

Finally we need to update our column sums. This is almost too easy as we have that wonderful gift from TrueGrid, ColumnSum. We simply use that to update our sums, with a bit of special handling to account for the fact that our sixth column is in fact the sum of table2. Refer below:


That's all the code required. Unbound mode scares some people... perhaps it oughtn't to.

Apex Software is releasing the OCX version of TrueGrid Pro in December 1995, priced at $299. The upgrade from TrueGrid Pro 2.1 will be priced at $189, upgrade from TrueGrid Standard will be $259. For further sales and technical details please drop us a note at orders@gui.com.au or contact GUI Computing on (03) 9804 3999.


[HOME] [TABLE OF CONTENTS] [SEARCH]