Home Forums WPF controls Xceed DataGrid for WPF Sort causes unexpected scroll-down

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26246 |

    I have a sample DataGridControl with 36 rows. The vertical sizing of the grid allows it to show 25 rows at a time. You have to scroll to see the remaining 11 rows. If the grid is scrolled to the top and I click one of the column headers, it sorts ascending. Fine so far.

    Then, if I click the same column header again, it sorts descending, which is expected, but the grid gets scrolled so that only one row is visible. If you look at the draggable scroll slider, it has shrunken to its minimum size and is all the way at the bottom of the scroll track. If you then drag the slider all the way up, it refreshes and everything is normal again.

    Just thought you’d like to know about this unusual behavior (if you don’t already).

    -Dan

    Imported from legacy forums. Posted by Daniel (had 4662 views)

    User (Old forums)
    Member
    Post count: 23064

    We have noticed this issue as well. It has been confusing to users, because they think that it’s hiding the other rows. They don’t realize that they’ve just been scrolled off the visible area.

    In general, it seems you can scroll until the last row is the only one left showing. Is there a way to stop the scrolling when the last row is displayed at the bottom of the visible grid area?

    Imported from legacy forums. Posted by Jason (had 1310 views)

    User (Old forums)
    Member
    Post count: 23064

    I have noticed this happening as well with my Grid.  [:O]

     

    Imported from legacy forums. Posted by Dave (had 484 views)

    Xceed Support
    Member
    Post count: 5658

    This can happen if the current row changes position when the sort occurs and ends up in the “last page” of rows. I am not sure if something was done (or could be done) in the upcoming version to change this behavior.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 348 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    Probably you are talking about collapsing of the entire DataGrid to just one row high. If this is the case with you, just try setting MinHeight of the DataGridControl to the size of your content area. To support resizing you might need to set MinHeight as an when the form resizes.

    Hope it works for you.

    Imported from legacy forums. Posted by Abdullah (had 797 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m getting this when binding to a BindingList<DataItem> and items are added to the collection. Is there any way to prevent the scroll down in v3.1? Else, can anyone suggest a workaround to maintain performance>?

    Imported from legacy forums. Posted by tommy (had 417 views)

    User (Old forums)
    Member
    Post count: 23064

    I have also observed  this kind on behavior. Probably when any of the grid’s row is in selected state then the after sorting it the xceed grid tries i to put in the visible area and if that row has to come at last so it squeezes the grid to make it at top. I tried with setting the Min and Max height but the behavior remains the same.

    -Saurabh

    Imported from legacy forums. Posted by Saurabh (had 2758 views)

    User (Old forums)
    Member
    Post count: 23064

    A possible solution (which I use) is:

    When you set the grid’s ItemsSource, create a collectionChanged event handler for the SortDescriptions:

          DataGridCollectionView view = this.ItemsSource as DataGridCollectionView;
          ((INotifyCollectionChanged)view.SortDescriptions).CollectionChanged +=
                                              new NotifyCollectionChangedEventHandler(this.SortCollectionChanged);

    In the handler, I invoke teh dispatcher to call my function to set the first item as selected using the Render priority:

        private void SortCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
          //Select first item, but only if no grouping is active
          DataGridCollectionView dgcvData = this.ItemsSource as DataGridCollectionView;
          if (dgcvData != null && dgcvData.GroupDescriptions.Count == 0)
          {
            Dispatcher.BeginInvoke((Action)(() => SelectFirstItemInGrid()), DispatcherPriority.Render, null);
          }
        }

        private void SelectFirstItemInGrid()
        {
          if (this.Items != null && this.Items.Count > 0)
          {
            object firstItem = this.Items.GetItemAt(0);
            this.CurrentItem = firstItem;
            this.SelectedItems.Clear();
            this.SelectedItem = firstItem;
          }
        }

    You may need to adapt the logic if you need a different item selected, but this does stop only 1 row being displayed after a sort has happened.

    Imported from legacy forums. Posted by Derek (had 2811 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the tip Derek. Works well.

    Imported from legacy forums. Posted by Daniel (had 1053 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.