2013-01-17 5 views
0

내 데이터 그리드에서 사용자가 일부 셀을 편집 할 수있게 허용합니다.이 셀을 편집 한 후 데이터베이스 변경을 커밋하고 싶습니다. 이 문제를 해결하기 위해 온라인 리소스를 찾는 데 문제가 있습니다.셀 값 및 위치 가져 오기 편집 셀 이벤트

가 나는라는 이벤트 사용

CellEditEnding을하지만 이벤트는 행과 골 방법 변경된 셀의 날을 제공합니다. 이것들을 사용하여 셀 자체를 찾고 값을 얻으려면 어떻게해야합니까?

답변

3

그럴 수이 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; 
     } 
+0

오류 비 제너릭 메서드 'System.Windows.FrameworkElement.GetVisualChild (int)'형식 인수를 사용할 수 없습니다 – user781439

+0

내 대답 – AbZy

+0

편집하고이 네임 스페이스를 포함하는 것을 잊지 마세요 using System.Windows.Controls.Primitives; – AbZy

관련 문제