By default UI virtualization is On for Datagrid which means only visible containers are generated.
In case you want to get dataGridRow or cell which is not visible you have to scroll down to that row manually from code behind so that its container gets generated. Refer this article here to manually scroll dataGridRow into view.
OR
Disable UI virtualization Off on dataGrid (in case don't want to scroll down) by setting VirtualizingStackPanel.IsVirtualising to false on your datagrid.
<DataGrid VirtualizingStackPanel.IsVirtualizing="False"/>