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
125
Controlling RowScrollRegion with updating DataSource
posted

Version - 9.2.20092.2042

I have an UltraGrid bound to a BindingSource, where the DataSource is a BindingList<T> and new records are added to the list.  Each record has a time stamp property/column and the typical usage is to sort by the time stamp column in descending order, i.e. the latest record appears at the top.

If the user scrolls down to look at a particular record, it can be annoying when new records come in because the visible position of the row changes (moves lower in the grid).  I have the following code to try to work around this, but it seems the call to set the "FirstRow" on the RowScrollRegion is completely ignored.

private void _grid_AfterRowRegionScroll(object sender, RowScrollRegionEventArgs e) {

_firstVisibleRow = e.RowScrollRegion.FirstRow;

}

private void _bindingSource_ListChanged(object sender, ListChangedEventArgs e) {

_grid.DisplayLayout.Bands[0].SortedColumns.RefreshSort(false);

if (_grid.DisplayLayout.RowScrollRegions[0].ScrollPosition != 0 && _firstVisibleRow != null)

  _grid.DisplayLayout.RowScrollRegions[0].FirstRow = _firstVisibleRow;

}

I've also confirmed that _firstVisibleRow is being set to the correct row and is still the correct row when setting "FirstRow" property.

Am I making an incorrect assumption that FirstRow should adjust the scroll region to make this row the first visible row?

Parents
No Data
Reply
  • 125
    posted

    After hacking around a bit this code is working for me...

     

    private void _grid_InitializeRow(object sender, InitializeRowEventArgs e) {

    _grid.DisplayLayout.Bands[0].SortedColumns.RefreshSort(false);

    if (_firstVisibleRow != null)

    _grid.DisplayLayout.RowScrollRegions[0].ScrollPosition = _firstVisibleRow.VisibleIndex;

    }

     

    I had to change the call back to InitializeRow on the Grid as opposed to the ListChanged on the BindingSource because the latest row was not being sorted property - it was appearing in the last row.

    Curious that setting scroll position works, but not setting FirstRow, is this a bug or intended? 

Children
No Data