2014-06-08 2 views
1

my DataGrid SelectionMode = "Single"설명 열이나 다른 열의 셀을 클릭 할 때마다 첫 번째 셀의 셀 포커스를 전환해야합니다.wpf datagrid 첫 번째 셀을 프로그래밍 방식으로 선택

이 내가

private void dgvConfig_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
    { 
     DependencyObject dep = (DependencyObject)e.OriginalSource; 
     // iteratively traverse the visual tree 
     while ((dep != null) && 
       !(dep is DataGridCell) && 
       !(dep is DataGridColumnHeader)) 
     { 
      dep = VisualTreeHelper.GetParent(dep); 
     } 

     if (dep == null) 
      return; 

     if (dep is DataGridColumnHeader) 
     { 
      string columnHead = ""; 
      DataGridColumnHeader columnHeader = dep as DataGridColumnHeader; 
      columnHead = columnHeader.Column.Header.ToString(); 
      LoadGridview(columnHead); 
      //MessageBox.Show(columnHeader.Column.DisplayIndex.ToString()); 
     } 

     if (dep is DataGridCell) 
     { 
      DataGridCell cell = dep as DataGridCell; 
      string cellName = cell.Column.Header.ToString(); 

      if (cellName.Equals("Description")) 
      { 


       cell.Focus(); 
       string datagridselect; 
       //datagridselect = DataGrid.SelectedIndexProperty[] 
       //var cellInfo = dgvConfig.SelectedCells[0]; 
       //var xt = dgvConfig.CurrentCell.Column. 

       // the prob is I cant seem to access an array to move the focus to the first column of that selected row 


      } 

     } 


    } 

답변

0

에 시도 내 코드는 시도 적이있다 :

private void dgShow_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) 
    { 
     foreach(DataGridCellInfo info in dgShow.SelectedCells) 
     { 
      if(info.Column.Header.ToString()=="Name") 
      { 
       dgShow.CurrentCell = info; 
       break; 
      } 
     } 
    } 
+0

대! 많은 감사합니다 !!! –

관련 문제