I need to add some “total rows” to a table. The code I am currently using for the sub totals is:
DataRow shRow = ds.Tables[0].NewRow();
shRow["a"] = "SubHead";
shRow["b"] = "Wheel Subs";
shRow["c"] = totalWheels;
Since I need totals and sub totals and sub sub totals I have to cut and paste this code (changing the values) for each new sub total.
I would like to have a function that takes the current table and values and adds the new row.
Something like:
public DataRow SubRow(DataTable ResultsTable, string SubHead, string SubHeader, string SubHeadValue)
That would then update the table in the main function.
Thanks for any help.
I just can’t ‘pass’ the table to and from the new function.
Whats wrong with that?
Usage:
By the way, this will not add the row to the table, but only create a row that can fit into the table appropriately. If you actually want to ADD the row to the table, you can do:
That will add a row with the given values to the Add method to the datatable, and return the row that has been added.