The code project one looks quite good but does not appear to have any tollerance for controls that have their own child controls.
To make it work with the datagrids Child Controls that have their own Child Controls, you will need to add the following:
else if (control.HasControls)
{
values.AddRange(GetValuesArray(control.Controls));
}
at the end of the if statement on the GetValuesArray method.
WARNING: You are creating a recursive loop! This is sometimes bad practice, but in this case should be safe.