I have a grid in a multi-user application. It needs to refresh it’s data periodically, but I would like to keep the first visible row the same after the refresh. The way the refresh works is, it regenerates the dataset. I store the index of the FirstVisibleRow by: topRow = Me.grdOrders.DataRows.IndexOf(Me.grdOrders.FirstVisibleRow) and then after the refresh re-set the first visible row by: Me.grdOrders.FirstVisibleRow = Me.grdOrders.DataRows.Item(topRow)
This works fine until you group by a column. Then, if the firstvisiblerow is a groupmanagerrow, it does not work and I can’t seem to find any way to make it work.
I inherited this application after a different programmer quit. Is there a way to fix this, or is there just a better way to go about it by not regenerating the dataset or…
I really appreciate any help.
Imported from legacy forums. Posted by dzins (had 2074 views)
What you could try: check to see if the FirstVisibleRow is a GroupManagerRow. If it is, get the ParentGroup, get the first DataRow from that group (through the GetSortedDataRows-method), and keep the index of that row. When refreshing, find that row, get the ParentGroup, and set the FirstVisibleRow of the grid to the first row in the HeaderRows of that group.
Before the refresh: Dim topRowIsGMR As Boolean Dim topRow As Xceed.Grid.Row = Me.grdOrders.FirstVisibleRow Dim topRowIndex As Int32
If topRow Is Xceed.Grid.GroupManagerRow Then topRowIsGMR = True topRowIndex = Me.grdOrders.DataRows.IndexOf(topRow.ParentGroup.GetSortedDataRows().Item(0)) Else topRowIsGMR = False topRowIndex = Me.grdOrders.DataRows.IndexOf(topRow) End If
After the refresh: If topRowIsGMR Then Me.grdOrders.FirstVisibleRow = Me.grdOrders.DataRows.Item(topRowIndex).ParentGroup.HeaderRows.Item(0) Else Me.grdOrders.FirstVisibleRow = Me.grdOrders.DataRows.Item(topRowIndex) End If
PS: this code has not been tested, and might not be valid VB.NET (I’m a C# programmer)
Imported from legacy forums. Posted by Tommy (had 3202 views)