BUG: DBGrid on a Modal Form Can Cause a Program to HangLast reviewed: November 19, 1996Article ID: Q150206 |
The information in this article applies to:
SYMPTOMSA program hangs if a DBGrid control is placed on a Modal Form, which itself was invoked from a Modal form from an MDIChild window, and the form containing the DBGrid is then closed. Usually the window receiving the focus after the form with the DBGrid control is closed begins to flash, and does not respond to user input.
STATUSMicrosoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. Microsoft is researching this issue and will post new information here in the Microsoft Knowledge Base as it becomes available.
WORKAROUNDShow the form containing the DBGrid in a non-modal fashion, and disable the other forms in the project until the non-modal form is dismissed. The routine below shows a form that appears as a modal form:
Public Sub ShowModalForm(frmTarget As Form) Dim c As Collection Set c = New Collection 'Disable all the forms For Each ofrm In Forms If ofrm.Enabled = True Then c.Add ofrm ofrm.Enabled = False End If Next ofrm 'Now show the target form non-modal frmTarget.Show 'If the frmTarget was disabled by the loop above '(because it was invisible) make sure it is now enabled frmTarget.Enabled = True 'Sit in a loop until the target form is dismissed Do While frmTarget.Visible = True DoEvents Loop 'FIX: Unload the Form UnLoad frmTarget 'We have left the loop, so the dialog has been closed 'Now Enable the forms that were disabled, and exit the procedure For Each ofrm In c ofrm.Enabled = True Next ofrm End SubBecause a non-modal form cannot be shown from a modal form, the routine above must also be used to show the form prior to the modal form containing the DBGrid control.
MORE INFORMATION
Steps to Reproduce Problem
'FIX: Flag to avoid unloading the form when the user closes it Private mblnIgnoreUnload as boolean 'FIX: Additional Code for Form_Load of Form2 Private Sub Form_Load mblnIgnoreUnload = True End Sub 'FIX: Additional Code for Form_QueryUnLoad of Form2 Private Sub Form_QueryUnLoad If mblnIgnoreUnload Then Me.Hide ' Make Form2 Invisible Cancel = True ' Do not unload Form2 mblnIgnoreUnload = False ' Next time we come here unload Form2 End If End Sub Private Sub Command1_Click() ShowModalForm Form2 End Suband change the Command1_Click event in Form2 to:
Private Sub Command1_Click() ShowModalForm Form3 End SubNow the forms correctly display and act like Modal forms, but the program does not hang when Form3 is dismissed.
|
Additional reference words: 4.00 vb4win vb4all buglist4.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |