tags:

views:

3

answers:

0

HI,

I have a datagrid (from wpf toolkit) which is binded to an observable collection . There are two buttons "Up" and "Down" which moves the selected row accordingly. For eg: If there are 10 items in the datagrid and if I select the 4th item and press "Up" arrow ,then the 4th item will be moved to 3rd item and previous 3rd item will be 4th item. ie swapping with previous item. Similarly "Down" arrow the other way.

private void BtnUpArrowClick(object sender, RoutedEventArgs e) {

  try
  {
    btnDownArrow.IsEnabled = true;
    currentRow = grdSeqData.SelectedIndex;
    if (currentRow == 0)
    {
      btnUpArrow.IsEnabled = false;
    }
    else
    {
      upRow = currentRow - 1;
      if (upRow >= 0)
      {
        sequenceDataList.Move(currentRow, upRow);
        currentRow = upRow;
      }
      else
      {
        btnUpArrow.IsEnabled = false;
      }
    }
  }
  catch (Exception ex)
  {
    CatchExeption(LanguageHandler.GetCurrentCultureText("EventUpArrow_Exception"), ex);
  }
}

The above code work fine when the datagrid is not sorted. When i sort the datagrid via header click, and then do the "Up" or "Down" operation nothing is reflected in the datagrid.

The view is getting sorted where as my binded collection remains the same. So i tried to move the collection from view but in vain.

ICollectionView view = CollectionViewSource.GetDefaultView(grdSeqData.ItemsSource) as ListCollectionView; view.MoveCurrentToNext();

I think when the datagrid sortdescription is applied, then the view will not move accordingly. Please help.