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
455
Maintain Active Row and Scroll Position between Grid Refresh
posted

Hi,

I have a win grid which is bound to list of custom application object (MarketDataItem), after every minute the data is re read from the application and bound to grid again. Also before refresh the I store the current  active row and scroll position and after the refresh I set them but this produces a flicker effect on the grid, is there a better way to do this?

 int keyField;

int scrollPosition;

UltraGridRow lastActiveRow;

keyField = (grid.ActiveRow.ListObject as MarketDataItem).Key;

scrollPosition = grid.ActiveRowScrollRegion.ScrollPosition;

lastActiveRow=null;

grid.SetDataBinding(getData(), null, true, true);

if (lastActiveRow != null){

grid.ActiveRow = this.lastActiveRow ;

}

grid.ActiveRowScrollRegion.ScrollPosition = scrollPosition;

 

private void grid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
 {
            MarketDataItem item = e.Row.ListObject as MarketDataItem;
            if (item != null)
            {
                if ( item.key == this.keyField )
                {
                    this.lastActiveRow = e.Row;
                }
            }

}

 

Also I have seen many responses where the suggested answer is not to rebind the data to the grid, but can some one suggest how can I program the above code so that I don't need to rebind. (One of the field lastPrice in the MarketDataItem object changes betwen each refresh so basically all the rows changes between each refresh). A small sample would really be appreciated.

 

Parents
  • 469350
    Suggested Answer
    Offline posted

    A better way to do this without rebinding the grid would be to simply update the data in the data source, rather than changing the entire data source.

    If that's not feasible, then you might be able to reduce or remove the flicker by surrounding your code in a BeginUpdate/EndUpdate block.

    Call BeginUpdate before you set the grid's DataSource. Then set the ActiveRow and scroll position, then call EndUpdate.

    Also.... does the code you have here work? The scrollposition code you have here is okay. But storing the ActiveRow and then re-setting it probably will not work. Once you set the DataSource on the grid or call SetDataBinding, all of the existing rows in the grid are destroyed and a completely new set of rows is created based on the new datasource. So the lastActiveRow you are storing here will not exist in the grid when you try to set it. You would have to store some key value from the row and then find the matching row.

Reply Children