Object Reference > True DBGrid Events > PostEvent Event |
PostEvent Event
The PostEvent event is used in conjunction with the PostMsg method to postpone operations that are illegal within the grid's events.
object_PostEvent (ByVal MsgId As Integer)
Arguments
MsgId is an integer that identifies the message posted by the PostMsg method.
If the PostMsg method is called, the grid will fire the PostEvent event with the MsgId of the corresponding PostMsg invocation after all pending operations are completed. You can then safely perform all desired operations in the PostEvent event.
For example, it is not possible to perform the Data control's Refresh method within the grid's AfterUpdate event because database operations are still pending, and the refresh cannot be tolerated. Instead of performing the refresh in the AfterUpdate event, you can call the PostMsg method (with a MsgId value of 1, for instance). After all pending database operations are completed, the grid will fire the PostEvent event. You can then perform the refresh operation safely in this event, after confirming that the MsgId argument passed in is 1.
The special case where MsgId is zero is used to clear any pending PostMsg invocations that have not yet been processed. A PostEvent event will fire for this case.
The following code illustrates a typical PostEvent handler:
Private Sub TDBGrid1_PostEvent(ByVal MsgId As Integer)
Select Case MsgId
Case 0
Exit Sub
Case 1
Data1.Refresh
Case 2
' Process other postponed operations.
End Select
End Sub
Note
Take care to avoid recursive situations when using PostMsg and PostEvent.