日期:2014-05-17 浏览次数:20887 次
int i = 0;
private void button2_Click(object sender, RoutedEventArgs e)
{
//i取具体的值行
DataGridRow dr = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(i);第
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(dr);
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(0); //取第0列每行单元格
cell.Focus();
}
public static 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);
}
&n