2012-06-17 6 views

답변

0

당신은 단순히이 확장

public static DataGridRow GetSelectedRow(this DataGrid grid) 
{ 
    return (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem); 
} 

을 방법 - 사용할 수 있으며 (귀하의 경우 0) 기존 행과 열 ID로 데이터 그리드의 셀을 얻을 수 있습니다 :

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; 
} 

확인 자세한 내용은이 링크 - Get WPF DataGrid row and cell

0
var firstSelectedCellContent = this.dataGrid.Columns[0].GetCellContent(this.dataGrid.SelectedItem); 
var firstSelectedCell = firstSelectedCellContent != null ? firstSelectedCellContent.Parent as DataGridCell : null; 

당신이 할 수있는이 방법 DataGridCell 및 DataGridCell 자체의 내용 인 FrameworkElement를 가져옵니다.

DataGrid에 EnableColumnVirtualization = True이 있으면 위의 코드에서 null 값이 나타날 수 있습니다.

특정 DataGridCell에 대해 데이터 소스의 실제 값을 가져 오려면 좀 더 복잡합니다. DataGridCell은 백업 데이터 소스의 여러 값 (속성)으로 구성 될 수 있으므로 일반적으로이 작업을 수행 할 수있는 방법이 없으므로 특정 DataGridColumn에 대해이 작업을 처리해야합니다.

관련 문제