Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
Moving a record up / down
posted

I'm trying to select a record then have a button that moves up / moves down the record.  the following code works one way, but when i try to go the other direction there is a "datachanged" (according to snoop) that shows a type asterik on the line and it gets hung there and won't go the other direction.  i noticed in the datapresentergeneric _exporess.xaml datachanged was under recordselector but no key was attached. any thoughts?  Here's my code.  I have two columns, the second column has the order then i resort.

internal void HandleMoveUp(object sender, ExecutedRoutedEventArgs args)
        {
            if (gridSelectedPreferences.SelectedItems.Records.Count > 0)
            {
                DataRecord dr = gridSelectedPreferences.SelectedItems.Records[0] as DataRecord;
                if (null != dr)
                {
                    int newNumber = (int)dr.Cells["Order"].Value;
                    int oldNumber = newNumber--;
                    int newRow = newNumber - 1;

                    gridSelectedPreferences.ExecuteCommand(DataPresenterCommands.StartEditMode);
                    dr.Cells["Order"].Value = newNumber;
                    gridSelectedPreferences.ExecuteCommand(DataPresenterCommands.EndEditModeAndAcceptChanges);
                    dr.Update();
                   
                    this.gridSelectedPreferences.ExecuteCommand(DataPresenterCommands.StartEditMode);
                    ((DataRecord)this.gridSelectedPreferences.ViewableRecords[newRow]).Cells["Order"].Value = oldNumber;
                    this.gridSelectedPreferences.ExecuteCommand(DataPresenterCommands.EndEditModeAndAcceptChanges);

                    OrderGridRecords();

                }
            }
        }

 

  private void OrderGridRecords()
        {

            //// setup grid for sort by after number change
            FieldSortDescription sortDesc = new FieldSortDescription();
            sortDesc.FieldName = "Order";
            FieldSortDescriptionCollection fieldSort = gridSelectedPreferences.FieldLayouts[0].SortedFields;
            FieldLayout layout = gridSelectedPreferences.FieldLayouts[0];
            fieldSort.Clear();
            sortDesc.Field = gridSelectedPreferences.FieldLayouts[0].Fields[1];
            layout.SortedFields.Add(sortDesc);

        }