tags:

views:

33

answers:

1

I am trying to figure out a calculation I can perform in C# to determine the rows per column. Let's say I know I am going to have 3 columns and my record count is 46. I know that I can mod the results to get a remainder, but I would like something more efficient than what I have tried. So I know I will have 16 rows per column with a remainder of 14 for the last column, but what is the best way to loop through the resutls and keep counts.

+1  A: 

Integer divsion will give you the number of complete rows (46 / 3 = 15). You then check the modulus to see if you have any leftover (46 Mod 3 = 1; yep, you have one column to put in a final extra row.)

To loop through, just check the modulus of the current record index (zero-based) with your column count. That modulus is the (zero-based) column index. If it equals 0, you start a new row.

But from your question, it sounds like you already got this far. So am I misunderstanding the question?

Dave
I think where I messed up is that I had the division number set to something other than an integer so the decimal was throwing me off!!! Thanks
DDiVita