2012-04-12 2 views
1

DataGrid (.net 프레임 워크 3.5, WPFToolKit)가 있습니다. 그리고 나는 어떤 세포의 경계 (왼쪽 또는 오른쪽)를 바꾸고 싶다. 하나, 둘, 셋. 그러면 어떻게 단일 셀에 액세스 할 수 있습니까? 그리고 그것은 가능한가? 일부 솔루션을 찾았지만 .net 4.에 해당합니다.DataGrid에서 셀을 가져 오는 방법은 무엇입니까?

답변

2

DataGrid를 확장하고 다음을 추가 할 수 있습니다. 참고 : 이는 단지 샘플 일 뿐이므로 일부 처리를 수행 할 필요가 없습니다. 뭐하는 거지 :

public DataGridCell GetCell(int row, int column) 
    { 
     var rowContainer = GetRow(row); 

     if (rowContainer != null) 
     { 
      var presenter = FindVisualChild<DataGridCellsPresenter>(rowContainer); 
      if (presenter == null) 
       return null; 

      // try to get the cell but it may possibly be virtualized 
      var cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column); 
      if (cell == null) 
      { 
       // now try to bring into view and retreive the cell 
       ScrollIntoView(rowContainer, Columns[column]); 
       cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column); 
      } 
      return cell; 
     } 
     return null; 
    } 

    public DataGridRow GetRow(int index) 
    { 
     var row = (DataGridRow)ItemContainerGenerator.ContainerFromIndex(index); 
     if (row == null) 
     { 
      // may be virtualized, bring into view and try again 
      ScrollIntoView(Items[index]); 
      row = (DataGridRow)ItemContainerGenerator.ContainerFromIndex(index); 
     } 
     return row; 
    } 

FindVisualChild의 정의는, this site 봐.

+0

감사합니다. GetRow는 잘 작동합니다. 그러나 GetCell에는 DataGridCellPresenter가 필요합니다. .net 3.5에 대한 것이 있습니까? 나는 찾지 못했다. –

+0

오, 죄송합니다. 죄송합니다. 나는 그것을 발견했다. 잘못된 네임 스페이스를 사용했습니다. –

관련 문제