0

I have the following code where I am attempting to count the rows under each grouping/band in a DataTable. This is currently counting ALL rows in the specified band index and returning that value to all band1 rows. I need a way of counting rows under each band in band1 and not all rows under band1, then return that value to each summary band. This is not the end result desired but I think I can finish if I can just get each band to have a unique value for rows under it rather than all rows applying the same specified condition.

foreach (DataRow rows in dataSetDS.Tables["dataTable1_band1"].Select())
            {
                rows["column"] = dataSetDS.Tables["dataTable1_band2"].Rows.Count.ToString();
            }

Current output to Excel using syntax above. enter image description here

Desired output:

enter image description here

AlBundy
  • 11
  • 6
  • I'm afraid I don't understand your question, can you provide more details, or try explaining your requirement differently? What does your database look like and what are you trying to achieve with it? – Mario Z Apr 20 '22 at 03:51
  • I have a datatable that I am exporting to Excel with GemBox. Setting drills using SetColumnDrill and then applying with GetDrillInfo to create bands. Trying to loop through the child rows for each row in _band1 to count the number of rows under them. The code above is counting all _band2 rows and updating the cell with that value rather than the number of childrows under each _band1 row. Let me if this helps at all. Updating initial post with picture. – AlBundy Apr 20 '22 at 13:37
  • Currently the column count column is set to SetColumnSubtotal. The endgame here, which I think I can achieve once I can find a way to access childrows for each row in _band1, is to change that value to the last rows value which is why I'm trying to count the childrows for each row in _band1. – AlBundy Apr 20 '22 at 13:51
  • I can't understand very well the problem, but I think that in "foreach" block you should consider only for the band2 that belongs to current band1, not to all the table. – ZanoOnStack Apr 21 '22 at 16:22

0 Answers0