Setting Values
Setting Grid values is best left to the control panel.
However, you can set the repeater field type value programmatically with a grid model instance:
$entry->example = $grid;
You can set the value with a collection of grid instances too:
$entry->example = $collection;
Lastly you can set the repeater field type value with an array of grid IDs:
$entry->example = [7, 8];