When refreshing an ultragrid I have been having sporadic (or what I thought were sporadic) problems where the grid would go black or flash before the grid was refreshed.
As I have done some more testing, I have found that the grid only seems to exhibit this behavior if you are refreshing the grid from a point where the numbers of rows in the grid does NOT completely fill the viewport (there is no vertical scroll bar). That is, if I refresh the data and bind to the grid and the grid already had more rows than were visible in the viewport (there IS a vertical scroll bar), I don’t get this flash/black grid behavior.
I have tried wrapping the grid refresh process with Suspend/Resume Layout and Begin/End Update both on the grid itself, its parent control, and the form all to no avail.
Thanks in advance for any assistance.
I have figured this out. While I was wrapping the entire process of refreshing the data set and the grid with Suspend/Resume Layout, one of the methods that I was calling was running EndUpdate() against the grid that I was refreshing. Once I removed that, the refresh works fine.
I am not sure how to answer your question aside from just showing you the code...
Below is the code that executes each time the grid is "refreshed" with a new set of data...
I hope this make sense to you...
I have left out stuff that does not reference the grid at all.
UltraGrid1:PerformAction(UltraGridAction:FirstRowInGrid).
ultraGrid1:DisplayLayout:Override:HeaderClickAction = HeaderClickAction:Select.
GetFirstBatch().
METHOD PUBLIC LOGICAL GetFirstBatch ( ): System.Windows.Forms.Cursor:Current = System.Windows.Forms.Cursors:WaitCursor. batchGrid:BeginUpdate().
ClearData(). /* code for this method is below */
GetTopBatch(). /* code for this method is below */
batchGrid:DisplayLayout:Override:HeaderClickAction = HeaderClickAction:Select. FormatColumns("Current"). /* this method just sets some props on the grid columns */ SetBatchState(). /* code for this method is below */ IF batchGrid:Rows:Count GT 0 THEN DO: batchGrid:ActiveRow = batchGrid:Rows:Item[0]. batchGrid:ActiveRow:Selected = TRUE. END. ELSE RETURN FALSE. RETURN TRUE. FINALLY: batchGrid:EndUpdate(). System.Windows.Forms.Cursor:Current = System.Windows.Forms.Cursors:Default. END FINALLY. END METHOD. /* GetFirstBatch */
METHOD PUBLIC VOID ClearData ( ): DEFINE VARIABLE queryHandle AS HANDLE NO-UNDO. DEFINE VARIABLE hTtHandle AS HANDLE NO-UNDO. DatasetHandle:EMPTY-DATASET NO-ERROR. ContextRowid = ?. queryHandle = DatasetHandle:TOP-NAV-QUERY(1). hTtHandle = DatasetHandle:GET-TOP-BUFFER(1):TABLE-HANDLE. queryHandle:QUERY-PREPARE("preselect each " + hTtHandle:Name). queryHandle:QUERY-OPEN(). CATCH eAppError AS Progress.Lang.AppError: UNDO, THROW eAppError. END CATCH. FINALLY: HasFirst = TRUE. END FINALLY. END METHOD. /* ClearData */
METHOD PUBLIC VOID GetTopBatch ( INPUT lCurrent AS LOGICAL ): ContextRowid = ?. FetchData(). /* code for this method is below */ BatchGrid:Refresh(). RecordCount = BatchSource:Count. SetBatchState(lCurrent). RETURN. END METHOD. /* GetTopBatch */
METHOD PUBLIC OVERRIDE VOID FetchData ( ): DEFINE VARIABLE cWhere AS CHARACTER NO-UNDO. DEFINE VARIABLE queryHandle AS HANDLE NO-UNDO. DEFINE VARIABLE hTtHandle AS HANDLE NO-UNDO. DatasetHandle:EMPTY-DATASET NO-ERROR. IF NOT(VALID-OBJECT(curDataAccess)) THEN curDataAccess = createDataAccessObject(). ASSIGN queryHandle = DatasetHandle:TOP-NAV-QUERY(1) hTtHandle = DatasetHandle:GET-TOP-BUFFER(1):TABLE-HANDLE . queryHandle:QUERY-PREPARE("preselect each " + hTtHandle:Name + " " + SortExpression). cWhere = SetWhereClause (INPUT curDataAccess:DatabaseTableName, INPUT FALSE). curDataAccess:WhereClause = cWhere. curDataAccess:BatchSize = BatchSize. curDataAccess:EventProcHandle = EventProcHandle. curDataAccess:fetchBatch (INPUT-OUTPUT DATASET-HANDLE DatasetHandle BY-REFERENCE, INPUT-OUTPUT ContextRowid). /* We'll unsubscribe the OffEnd event if we've gotten all records. */ IF ContextRowid EQ ? OR TRIM(ContextRowid) EQ "" THEN SubOffEnd(FALSE). ELSE SubOffEnd(TRUE). queryHandle:QUERY-OPEN(). CATCH eAppError AS Progress.Lang.AppError: UNDO, THROW eAppError. END CATCH. FINALLY: SetHasFirst(curDataAccess:DatabaseTableName). CheckBatchState(). END FINALLY. END METHOD. /* FetchData */
METHOD PUBLIC VOID SetBatchState ( INPUT lCurrent AS LOGICAL ): /* If we're in word search and done batching, enable column sorting */ IF WordSearchMode EQ TRUE AND IsBatched EQ FALSE THEN DO: BatchGrid:DisplayLayout:Override:HeaderClickAction = HeaderClickAction:Select. FormatColumns("NoChange"). END. IF VALID-OBJECT(BatchUtilityBar) THEN DO: IF IsBatched EQ TRUE THEN DO: BatchUtilityBar:SetGroupByEnableState(FALSE). END. ELSE DO: BatchUtilityBar:SetGroupByEnableState(TRUE). END. END. IF FetchingAll EQ FALSE AND IsBatched EQ FALSE THEN DO: BatchGrid:DisplayLayout:Override:HeaderClickAction = HeaderClickAction:Select. IF lCurrent THEN FormatColumns("Current"). ELSE FormatColumns("Reset"). END. BatchSource:Batching = NOT HasLast. IF NOT(Progress.Util.EnumHelper:AreEqual (BatchGrid:DisplayLayout:Override:HeaderClickAction,HeaderClickAction:ExternalSortSingle)) THEN BatchGrid:DisplayLayout:Override:HeaderClickAction = HeaderClickAction:ExternalSortSingle. SetScrollTip(). END METHOD. /* SetBatchState */
What exactly do you mean by "refreshing the grid?"