Basically you initialise at the beginning of the code your variable r to the number of rows -1, then later in your loop you are adding news rows:
int newRowIndex = tr.dtsender.Rows.Add();
So if at the beginning you have 0 rows r will be negative, and as you do not recalculate it the exception "Index was out of range. Must be non-negative and less than the size of the collection." will be throws as r is -1.
So... recalculated r before using it as the number of rows as changed: