Home Forums WinForms controls Xceed Grid for WinForms Updatable Grid Reply To: Updatable Grid

User (Old forums)
Post 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
if (_refreshGrid)
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[0]).Cells[refreshSelectedColumnIndex];

// Mark grid as being refreshed
_refreshGrid = false;

Any suggestions?

Thank you for your time.

Imported from legacy forums. Posted by GridMan (had 482 views)