关于如何获得DataGrid内的单元格

关于如何获取DataGrid内的单元格

DataGridRow rowContainer = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(rowIndex);
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);
 
// ...
 
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);
    else
      break;
  }
 
  return child;
}
上一篇:SQL基础之使用集合运算符进行多表查询(十二)


下一篇:jQuery EasyUI jquery.datagrid.js源代码