public System.Windows.Controls.DataGridRow GetRow(int index)
 {
     System.Windows.Controls.DataGridRow row = (System.Windows.Controls.DataGridRow)DataGrid2.ItemContainerGenerator.ContainerFromIndex(index);
     if (row == null)
     {
         // may be virtualized, bring into view and try again
         DataGrid2.ScrollIntoView(DataGrid2.Items[index]);
         row = (System.Windows.Controls.DataGridRow)DataGrid2.ItemContainerGenerator.ContainerFromIndex(index);
     }
     return(row);
 }
        public System.Windows.Controls.DataGridCell GetCell(int row, int column)
        {
            System.Windows.Controls.DataGridRow rowContainer = GetRow(row);

            if (rowContainer != null)
            {
                DataGridCellsPresenter presenter = GetVisualChild <DataGridCellsPresenter>(rowContainer);

                // try to get the cell but it may possibly be virtualized
                System.Windows.Controls.DataGridCell cell = (System.Windows.Controls.DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
                if (cell == null)
                {
                    // now try to bring into view and retreive the cell
                    DataGrid2.ScrollIntoView(rowContainer, DataGrid2.Columns[column]);
                    cell = (System.Windows.Controls.DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
                }
                return(cell);
            }
            return(null);
        }