그럴 수이 link
public static DataGridCell GetCell(this DataGrid grid, DataGridRow row, int column)
{
if (row != null)
{
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(row);
if (presenter == null)
{
grid.ScrollIntoView(row, grid.Columns[column]);
presenter = GetVisualChild<DataGridCellsPresenter>(row);
}
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
return cell;
}
return null;
}
에서 발견 된이 기능을 사용하여 이벤트 핸들러에서 호출 :
object cellvalue = DataGridCell(yourgrid, e.Row, e.Column.DisplayIndex).GetValue;
이 기능은 또한 GetCell()
함수 내에서 호출
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);
}
if (child != null)
{
break;
}
}
return child;
}
오류 비 제너릭 메서드 'System.Windows.FrameworkElement.GetVisualChild (int)'형식 인수를 사용할 수 없습니다 – user781439
내 대답 – AbZy
편집하고이 네임 스페이스를 포함하는 것을 잊지 마세요 using System.Windows.Controls.Primitives; – AbZy