Hi,
I have a UltraWinGrid inside a tab. When we refresh data, I want to only process visible rows for display purposes. The first issue I had was that on initial load, ActiveRowScrollRegion was not prepared properly, it does not contain any rows in it. What I did was call UltraGrid.Update() after data is loaded. This seems to prepare the ActiveRowScrollRegion for me to work with. Now I run into another issue. This Grid is located in one of several tabs user can select from. When user selects a different tab and then comes back to this tab, we do a data reload. During this data reload, I noticed that although the ActiveRowScrollRegion seems to still maintain the same amount of rows, but right after I update the data source, all the ListObject and ListIndex for the rows in the region were reset. However, the row in UltraGrid.Rows seems to be bound correctly with proper ListObject. Is there a method to refresh the ActiveRowScrollRegion so it'll update the ListIndex and ListObject for its rows?
One way I've found to trigger a refresh of ActiveRowScrollRegion is to either select a row or set active a row. But that requires me to keep track of current active row to persist through data loads, while originally that is managed automatically by the grid itself. It'd be much cleaner to still have Grid handle that.
Thanks
First of all, I was able to reproduce the problems you describe here with the ActiveRowScrollRegion not synchronizing its visible rows until the control paints. I suppose you could argue that the RowScrollRegion is a view and therefore tightly coupled with the visible UI, so it is possible that this is by design, but IMO it should just work, period. I'll leave it up to you as to whether you want to report it as a bug; considering that all you have to do to clear it up is force a repaint, it probably isn't worth the trouble.
That issue notwithstanding, I tried to reproduce the issue you described here but I was not able to. I suspect there are important details missing that are necessary to reproduce the problem. In any case, I posted the code I used to verify that the ListObject property returns the same DataRowView reference when accessed from a row in the control's Rows collection and a row accessed from the ActiveRowScrollRegion's VisibleRows collection. Take a look and see what you're doing that I'm not and if you can nail that down we'll take another look.
Please excuse the terrible formatting here, we seem to be having issues with pasting code.
// Cache refs to the old rows
RowScrollRegion oldRSR = this.grid.ActiveRowScrollRegion;
List<object> oldListObjects = new List<object>(oldRSR.VisibleRows.Count);
for ( int i = 0; i < oldRSR.VisibleRows.Count; i++ )
{
oldListObjects.Add(oldRSR.VisibleRows[i].Row.ListObject);
}
// Clear data source
this.grid.DataSource = null;
// Reset the data source
this.grid.DataSource = this.Table;
// Get a ref to the new RSR
RowScrollRegion newRSR = this.grid.ActiveRowScrollRegion;
// Force a repaint to wake up the RowScrollRegion
this.grid.Update();
// Iterate the RSR's VisibleRows collection and compare each
// row's ListObject to the one that was cached earlier.
for ( int i = 0; i < newRSR.VisibleRows.Count; i++ )
object oldListObject = oldListObjects[i];
object newListObject = oldRSR.VisibleRows[i].Row.ListObject;
// The references here will and should be different since a new
// DataRowView object was generated by the data source.
bool oldIsSame = object.ReferenceEquals(oldListObject, newListObject);
// The references here, however, are the same.
bool newIsSame = object.ReferenceEquals(this.grid.Rows[i].ListObject, newListObject);
The only thing missing, that I can think of, is that before we leave the tab containing the grid, we have an item selected. When I get back to the tab, that selection is cleared because of context change. However, the lost of ListObject happens right after I load the data. Our logic of determining which record to select has not run yet.
Thanks for the code sample, I might be able to extend from there. I take it there is no existing function that refreshes the RSR automatically then?