WPF中DataGrid的有关问题:1、根据row和col滚动至对应的DataGridCell并选择;2、选中某单元格怎么得到其row和col,在线急求。

WPF中DataGrid的问题:1、根据row和col滚动至对应的DataGridCell并选择;2、选中某单元格如何得到其row和col,在线急求。。。
WPF中DataGrid的问题:
1、根据row和col滚动至对应的DataGridCell并选择;
   会有滚动条出现的情况。
   以下是我现在的代码:
   
public DataGridCell GetCell(DataGrid dataGrid, int rowIndex, int columnIndex) 
        { 
            DataGridRow rowContainer = GetRow(dataGrid,rowIndex); 
            if (rowContainer != null) 
            { 
                DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
                if (presenter != null)
                {
                    DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);
                    if (cell == null)
                    {
                        dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[columnIndex]);
                        cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);
                    }
                    return cell; 
                }
            } 
            return null; 
        }

        public DataGridRow GetRow(DataGrid dataGrid, int rowIndex) 
        { 
            DataGridRow rowContainer = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);
            if (rowContainer == null) 
            { 
                dataGrid.UpdateLayout(); 
                dataGrid.ScrollIntoView(dataGrid.Items[rowIndex]);
                rowContainer = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);
            } 
            return rowContainer;
        }

        public T GetVisualChild<T>(Visual parent) where T : Visual 
        { 
            T child = default(T);
            int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
            for (int i = 0; i < numVisuals; i++) 
            { 
                Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
                child = v as T; if (child == null) 
                {
                    child = GetVisualChild<T>(v); 
                } 
                if (child != null) 
                { 
                    break;
                }
            } 
            return child;
        }

如果需要滚动:在GetVisualChild函数的GetChildrenCount得到的是0

请问诸位大大,如何破?
感谢感谢!!!!
------解决思路----------------------
http://download.csdn.net/download/duanzi_peng/8126501
下载DataGrid操作类。
------解决思路----------------------
引用:
第二个问题:
如何得到当前DataGrid选中单元格的row和col?
因为我一直需要刷新数据,如果同时修改,那么输入党员框中的值,很可能被原来的数据(刷新)重新覆盖。
此时,我的计划是这样:
希望得到当前选择的单元格的row和col,根据他们确定对应的数据。软后在刷新数据的函数中,暂停对这个数据的更新,如果用户放弃修改,在将刷新结果付给该数据。
但是:我得不到row和col。请问如何得到?
或者是否有其他解决方案?
谢谢!

你的需求都很蛋疼!选中的不刷新,其他的刷新WPF中DataGrid的有关问题:1、根据row和col滚动至对应的DataGridCell并选择;2、选中某单元格怎么得到其row和col,在线急求。
------解决思路----------------------
引用:
没有滚动的话,是没有问题的!滚动就会出现以上的问题。这是什么么原因造成的,如何解决?谢谢了!

parent 类型不应该是  Visual的吧,是DependencyObject类型的吧?
用这个方法测试一下。

public T GetChildObject<T>(DependencyObject obj, string name) where T : FrameworkElement  
        {  
            DependencyObject child = null;  
            T grandChild = null;  
  
  
            for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)  
            {  
                child = VisualTreeHelper.GetChild(obj, i);  
  
  
                if (child is T && (((T)child).Name == name 
------解决思路----------------------
 string.IsNullOrEmpty(name)))  
                {  
                    return (T)child;  
                }  
                else  
                {  
                    grandChild = GetChildObject<T>(child, name);  
                    if (grandChild != null)  
                        return grandChild;  
                }  
            }  
            return null;  
        }  

obj  传入你的父控件类型。
------解决思路----------------------
怎么看着这么复杂呢
要滚动到指定的col和row你,直接调用datagrid的ScrollIntoView不就完了,知道了rowIndex就可知道它的row对象