Hi,
I use a wingrid which auto refreshes every 5 seconds.The problem that I face is when the user scrolls down the grid, suddenly the grid refreshes and moves back up to the top.I want the grid to stay in the same scroll area after refreshing.I set the the first row as active row after every refresh.
So how to save the current scroll position and load the same back after refresh?Or can anyone suggest a better solution?
Thanks,
Abja
I'm not sure it's a good idea to call BeginInvoke on the delegate. You should probably be calling BeginInvoke on the grid or the form and passing in the delegate.
But if that didn't work, then it's most likely a moot point, anyway.
AndyCaignie said: That is something I don't understand. It would be something like this: int i = 0; int j = 5; i = j; and when you set a Watch on i it would still be 0 instead of 5, this is what happens with the DisplayLayout.RowScrollRegions[0].FirstRow property. It's not logical.
That is something I don't understand.
It would be something like this:
int i = 0;
int j = 5;
i = j;
and when you set a Watch on i it would still be 0 instead of 5, this is what happens with the DisplayLayout.RowScrollRegions[0].FirstRow property. It's not logical.
I'm not sure why this is happening. As I said above, my theory is that it's because the grouping has not completed yet or the FirstRow is getting changed again at some point after you said it, but I'm only guessing here, since I can't see the behavior.
Perhaps at this point, you should try to create a small sample project that demonstrates the problem and either post it here or Submit an incident to Infragistics Developer Support so we can check it out.
Ok, I successfuly managed to implement a delegate to a SetFirstRow Method. After the LoadData method I call this method through the delegate.BeginInvoke(null, null). This calls my SetFirstRow method, I checked this. But the FirstRow is still not changed.
I think it's something to do with the fact that you can't set a groupedbyrow as FirstRow or something like that. I have the Correct row stored, I set it:
not set to correct row <- ugvShipmentMovements.DisplayLayout.RowScrollRegions[0].FirstRow = ugvShipmentMovements.FirstRow; -> correct row
AndyCaignie said:I don't know quite yet if it's a time issue. The weird thing is that it works for datarows and not for groupbyrows.
This makes perfect sense as a timing issue. If the grid is not grouped, the rows are there. If it's grouped, the grouping is done asynchronously.
AndyCaignie said:About the BeginInvoke, I don't knwo how to implement this. Isn't that used for assynchronously calls and multithreading? Don't know for sure this is a good idea.
BeginInvoke is usually used to marshal across threads, but you can call it on the same thread. You just create a method that does what you need to do, then create a delegate to that method and call BeginInvoke with that delegate.
Do a search on this forum for BeginInvoke, I'm sure there are some sample code snippets posted.
I don't know quite yet if it's a time issue. The weird thing is that it works for datarows and not for groupbyrows.
I call the LoadData fucntion at several locations on the frmShipmentMovement Form, the refresh button click, the applyfilter method ... each time the data needs to be fresh.
The InitializeLayout Method is called before the LoadData Method when I debug.
About the BeginInvoke, I don't knwo how to implement this. Isn't that used for assynchronously calls and multithreading? Don't know for sure this is a good idea.
Okay, so it's pretty clear to me that this is a timing issue of some kind. You are setting the FirstRow on the grid and it's getting reset by something that happens after the LoadData method is called.
Where is LoadData being called from?
Perhaps it would be better to move the line of code that sets the FirstRow on the RowScollRegion of the grid to some later point, such as in the InitializeLayout event of the grid.
If that's no good, then another option would be to create a separate method that sets the FirstRow and instead of calling the method directly from LoadData, you use a BeginInvoke to call it. That will create a delay that might solve the issue.