User (Old forums)MemberJanuary 29, 2007 at 2:19 pmPost count: 23064
I have a grid with a few columns that can be updated (everything is done in the grid). I update the DB immediately upon changing a cell’s value using the ValueChanged event and flag the grid as needing refreshed. I then refresh the grid during the KeyUp or MouseDown events of each cell if an update has been made. I received errors if I refreshed during the ValueChanged event if I refreshed the grid at that time.
The way I’m doing now works well (even with sorting), but when grouping is introduced I run into problems. My question is, is there anyway to refresh a grid and maintain the scrolling position afterward? If there was a way I could store the scroll position before the refresh and then scroll the grid by that amount afterward that would be great.
Imported from legacy forums. Posted by GridMan (had 3891 views)User (Old forums)MemberJanuary 29, 2007 at 5:26 pmPost count: 23064
Have you tried using the FirstVisibleRow and FirstVisibleColumn properties? You save them before the update, and assign them back after the update.
Here is more <a href=”http://doc.xceedsoft.com/products/XceedGrid/How_to_bring_a_grid_element_into_view.html”>details</a> from our online help documentation.
Imported from legacy forums. Posted by André (had 298 views)User (Old forums)MemberJanuary 30, 2007 at 9:00 amPost count: 23064
Thanks for your reply.
Yes, I am using the FirstVisibleRow before saving. The grid isn’t wide, so I didn’t need to use the FirstVisibleColumn. Basically I have ValueChanged events for the 2 columns that are updatable, where the save is done. I tried refreshing at that point and received errors because I don’t think it had tried to set focus to the new cell yet. So, I set a variable that said the grid needed to be refreshed. Then I have a KeyDown event at the grid level and a MouseDown event for each cell that checks that variable and then refreshes that grid (since I know the focus had changed at that point). And this is good because it keeps you wherever you just clicked or navigated with the keyboard. The correct cells is also selected.
So when the first visible row is a datarow (and not a GroupManagerRow) it works fine, even when sorted. But since I was using the SortedDataRows collection to find the index to refresh to, it throws an error when calling the indexOf method when the first visible row isn’t a datarow. So, I made the first visible row be the row I just clicked on(currentRow) in that case so the grid does keep me on the record I just clicked on but the scroll position is usually different.
This is the code that does the refresh:
private void checkRefreshGrid()
// Check to see if the grid needs refreshing
ReadOnlyDataRowList sortedDataRows = grdContainerSlots.GetSortedDataRows(true);
int refreshFirstRowIndex = 0;
int refreshSelectedRowIndex = 0;
int refreshSelectedColumnIndex = 0;
// Keep track of the 1st visible row prior to refreshing
if (grdContainerSlots.FirstVisibleRow.GetType() == typeof(Xceed.Grid.DataRow))
refreshFirstRowIndex = sortedDataRows.IndexOf((Xceed.Grid.DataRow)grdContainerSlots.FirstVisibleRow);
// If the first visible row isn’t a DataRow (such as a GroupManagerRow).
refreshFirstRowIndex = sortedDataRows.IndexOf((Xceed.Grid.DataRow)grdContainerSlots.CurrentRow);
// Keep track of the currently Selected Row & Column prior to refreshing
refreshSelectedRowIndex = sortedDataRows.IndexOf((Xceed.Grid.DataRow)grdContainerSlots.CurrentRow);
refreshSelectedColumnIndex = grdContainerSlots.CurrentColumn.Index;
// Perfom search to refresh the grid
// Set 1st visible row to what it was prior to refreshing
sortedDataRows = grdContainerSlots.GetSortedDataRows(true);
grdContainerSlots.FirstVisibleRow = (Xceed.Grid.DataRow)sortedDataRows[refreshFirstRowIndex];
// Clear any selected rows
// Select same row & cell that was selected prior to refreshing
grdContainerSlots.CurrentCell = ((Xceed.Grid.DataRow)grdContainerSlots.SelectedRows).Cells[refreshSelectedColumnIndex];
// Mark grid as being refreshed
_refreshGrid = false;
Thank you for your time.
Imported from legacy forums. Posted by GridMan (had 482 views)User (Old forums)MemberJanuary 30, 2007 at 3:04 pmPost count: 23064
When you refresh the grid (most likely by filling the data table on which you are bound), the grid rebuilds itself completely. Therefore, there is no guarantee that there will be a row at the current index after the refresh. Basically, in this case, it is not possible to reposition the scroll as it was before, in all cases.
Imported from legacy forums. Posted by André (had 214 views)User (Old forums)MemberJanuary 31, 2007 at 9:24 amPost count: 23064
I think based on my work with xceed grid that if u make unbound grid and fill it with database query and if it has detail rows it become pain to do refreshing, so u need to avoid refreshes, make background changes into database, delete odr add rows or change the cell values without refreshing grid and allow users to be able to control the refresh event when they need to, also keep firstrow visible and simmilar stuff to enable user is on the same or next logical place in the grid after he make changes to the grid.
Imported from legacy forums. Posted by Ma (had 490 views)User (Old forums)MemberJanuary 31, 2007 at 2:46 pmPost count: 23064
This particular form doesn’t allow adding or deleting rows, which does make it a lot easier. As long as the first row was a datarow (and not a GroupManagerRow) I am able to keep the grid at the same position and keep the correct row and cell selected. If the first row wasn’t a datarow, after refreshing I have the first row being where the user just clicked. For the most part, I don’t think users will group on this form anyway. So it sounds like this is probably the best that I can do at this point.
Could this situation be a good candidate for a grid enhancement in the future?
Thanks everyone for your replies.
Imported from legacy forums. Posted by GridMan (had 4719 views)
- You must be logged in to reply to this topic.