I have a wingrid that I am trying to refresh the datasource. I need it to work like outlooks email program which allows emails to come in and keep the display on the current item. So if the user is scrolled half way down the grid, and the datasource is refreshed it doesn't pop the grid up to the top and the user is confused. This works great until the user has something in the outlook groupby area. If I run the code below, it then stops working, without this line it works fine. Is there a solution to this. I am using version 10.2.20102.2117
Me.UgridMessages.DisplayLayout.Bands(0).SortedColumns.Add("EnterDate", True, True)
What do you mean by "refresh the datasource"?
Is the grid scrolling to the top when you group by a column? Or not until later on when you add a row to the data source while the grid is grouped?
When you group by a column, the grid rows are moved under their respective GroupByRows. So this probably destroys the original row object and creates new UltraGridRows for the data rows. Which means there's no way the grid can maintain the scroll position, since the rows are no longer what they were.
If that is what's happening, then what you would have to do is store some sort of key information from the row before you group. Then you would have to loop through the grid rows recursively to find the new row with the same data, expand it's parent(s) and scroll it into view.
I am setting the groupbybox by Date and the screen shows everything correct, then I have a timer that say a minute later grabs a new object set, and sets the BindingSource.Datasource to the new object. When that event happens the grid jumps back to the top of the screen. Without the GroupByBox set the screen does not jump.
Hi,
Setting the DataSource property of the gird is a pretty destructive act. When you do this, the grid throws away all of the rows and the layout and builds a completely new layout to match the new data structure. There's no way the grid can link up the original rows with the new ones, since the BindingManager will give the grid a completely new set of rows from the new data source.
So it's usually a good idea to avoid setting the DataSource on the grid if you possibly can. It's better to update your existing data source with whatever new rows or whatever other changes you need, since the DataSource (assuming it's an IBindingList) will notify the grid of any changes.
Quite frankly, I don't know why your grid is not losing it's position when it's not grouped - it should be. Perhaps you already have some code in place to store the grid.ActiveRowScrollRegion.FirstRow property and this code is simply failing to account for the fact that the FirstRow might be a GroupByRow.