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.
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.
Mike,The code works, in the InitializeRow method for each row I check so see if it match the key data field (which is stored just before the grid is about to be refreshed) and if matching row is found I store the reference of the row and after the InitializeRow method I set it to active row.Also regarding your first suggestion, do you mean that after I set the initial DataSource for the grid any subsequent changes need to done the DataSource itself and not to grid. Some like belowList<MarketDataItem> list = GetData();//initial data source set upgrid.DataSource = list;//subsequent data setupList<MarketDataItem> list = grid.DataSource as List<MarketDataItem>;list.RemoveAll(); //since all the rows get changedlist.AddRange(GetData());Please advise, if possible please include a sample or point to a sample if already posted earlier.Thanks a lot.
Yes, if you simply alter the data in the datasource by removing, adding, or editing rows, then the grid will not be reset and lose all of it's state information like the selected rows and the scroll position.
Part of the problem might be that you are using a List<T>, though. A list is not really meant for binding and it doesn't notify the grid of changes. If you change your List<T> to BindingList<T>, then when you make changes to the data, they will automatically be reflected in the grid.
Hi Mike,
I am using ultragrid. when I am making some changes and saving the data.. my utlragrid is flickering little bit when saving data and refreshing. How to stop the flickering?
I'm not sure what kind of flickering you are referring to or exactly what your code is doing which is triggering it. So it's impossible to say how to stop it.
The first thing I recommend is that you get the latest service release. How to get the latest service release - Infragistics Community
If that does not help, we would probably need to see a small sample project demonstrating the issue in order to see what's causing it.