Database Programming Techniques > Refreshing the Display |
True DBGrid defers screen updates until they are needed by waiting until Windows enters an idle loop. This generally occurs when your code stops executing and the system is waiting for user input. You can simulate an idle loop in code by calling the Visual Basic function DoEvents, which causes all pending events to be processed.
In most cases, you need not be concerned with the grid's display operations and can concentrate on writing code that works directly with the database. However, if the structure of your data source changes, or you need to temporarily keep the grid from responding to database events, you can use the Refresh, ReBind, or ReOpen methods. If you are not using DataMode 1 - Unbound, these methods behave as follows:
This method simply forces the grid to repaint, and no database access occurs. The grid maintains all modified data in the current row, and the current cell position is unchanged. |
|
This method causes the grid to disconnect from and then reconnect to its data source. The grid rebinds all columns and refetches all data. Any data changed by the user (but not yet updated to the database) will be lost. The grid maintains the current row but not the current column. When data is redisplayed, the leftmost visible column becomes current, and the current row becomes the first row in the grid (unless all records are visible). |
|
This method is typically used following a Close method to reconnect the grid to its data source. The grid is repopulated and the current row is positioned to the row identified by an optional bookmark argument. If no bookmark is specified, then the current row reflects the current row of the data source. |
If you need to refresh a single column or row instead of the entire grid, you can use the RefreshCol or RefreshRow methods instead of Refresh. To refresh an individual grid cell, use the RefreshCell method of the desired Column object.
To maintain backward compatibility with the original unbound mode of DBGrid, the Refresh and ReBind methods behave as follows when the DataMode property is set to 1 - Unbound:
The grid refetches and redisplays all data by firing the UnboundReadData event. Any data changed by the user (but not yet updated to the database) will be lost. The grid maintains the current row but not the current column. When data is redisplayed, the leftmost visible column becomes current, and the current row becomes the first row in the grid (unless all records are visible). |
|
The grid refetches data by firing the UnboundReadData event, but it maintains any data changed by the user within the current row. When data is redisplayed, the current cell position and the grid display are unchanged. |