2014-11-14 4 views
0

다시 DataGrid에 문제가 있습니다 ... 이번 : 셀을 편집 할 때 어떻게 정렬을 끌 수 있습니까? 예를 들어DataGridColumn 정렬 켜기

:

enter image description here

나는 'A'마지막 표시되고 열이 정렬되어 있기 때문에 상단에 뛰어 추가 할 수 있습니다. 하지만 버튼에 머물러 있어야합니다. Visual Studio에서 설정 파일을 정렬하면 원하는대로 작동합니다. 작동하지 않는, enter image description here

내가 SortDirection을 다시 시도 : : 현재 VS에서 같은 예는, 그것을 자신을 시도 할 수 있습니다

private void dgVATINS_BeginningEdit(object sender, DataGridBeginningEditEventArgs e) 
    { 
     foreach (DataGridColumn col in dgVATINS.Columns) 
     { 
      col.SortDirection = null; 
     } 
    } 
+0

에서 CollectionChanged 이벤트에 이벤트 처리기를 추가하지 DataGrid에 대한 WPF – MrApfelstrudel

+0

@reggaeguitar 그는 당신이 제안한 링크가 Winforms에 관한 것이지만 WPF DataGrid로 작업하고 있음을 의미합니다. –

+0

아마도 이것? http://stackoverflow.com/questions/13401869/wpf-datagrid-clear-column-sorting – reggaeguitar

답변

0

발견 솔루션 :

/// <summary> 
    /// Resets the sorting. 
    /// </summary> 
    public void ResetSorting() 
    { 
     ICollectionView view = CollectionViewSource.GetDefaultView(dgVATINS.ItemsSource); // Gets the default view of the DataGrid 
     if (view != null && view.SortDescriptions.Count > 0) 
     { 
      view.SortDescriptions.Clear(); // Clears the sorting 

      foreach (DataGridColumn column in dgVATINS.Columns) 
      { 
       column.SortDirection = null; 
      }; 
     } 
    } 

그리고 이것은 DataGridView를 (Windows Forms의)에 대한 인 ObservableCollection<T>

void VATINS_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
{ 
    ResetSorting(); 
} 
0

Helper.SetGridViewSortState (this.dgv, DataGridViewColumnSortMode.NotSortable을); 시도하십시오이

+0

DataGirdView의 경우 DataGrid 용 솔루션 (WPF)을 찾고 있는데, – MrApfelstrudel

관련 문제