Bound Mode > Visual Basic Data Control Considerations > How True DBGrid reacts to Recordset changes |
When you bind a grid to a Data control, you are actually linking the grid to the underlying Recordset object, which is managed by the Data control. The Recordset object can be accessed directly using the Recordset property of the Data control:
Example Title |
Copy Code
|
---|---|
Data1.Recordset.MoveFirst |
This statement positions the record pointer to the first record in the Recordset.
You need not worry about keeping the grid synchronized with changes made to the Recordset, as this happens automatically. Modifying the Recordset is the preferred way to effect changes to the grid's display.
Here is how the grid responds to various operations performed on the Recordset associated with the Data control:
Positioning |
The grid's current row will change in response to a successful invocation of any of the following Recordset control methods: Seek, Move, MoveFirst, MoveLast, MoveNext, MovePrevious, FindFirst, FindLast, FindNext, and FindPrevious. If necessary, the grid will scroll to make the current row visible. The grid optimizes its response to these messages. For example, if your code performs a MoveFirst followed by 20 consecutive MoveNext calls, the grid will position only once, to the 21st row. Consult the Visual Basic Help for more information on the Recordset object's methods. |
Update |
The Recordset object's Update method causes the grid to write any changed data to the database. The update may be canceled in the Data control's Validate event. After the database is updated, the grid will clear the pencil icon in the record selector column. |
Delete |
True DBGrid reacts to the Recordset object's Delete method by removing the current row from the grid display. However, the Delete method does not change the current record, therefore the Bookmark property of both the grid and the Recordset still refers to the record that was just deleted. At this point, there is no current row in the grid, and its Row property returns -1. |
Requery |
This method causes the grid to refetch and redisplay all data. Any modifications made to the grid's current row that have not been updated to the database will be lost. After the Requery method is executed, the current cell will be the leftmost visible column of the first record, which will be displayed at the upper left corner of the grid. |