Why is MDI form minimized by MessageBox

  • Thread starter Thread starter Goran Djuranovic
  • Start date Start date
G

Goran Djuranovic

Hi all,
I have a VB.NET windows application that uses MDI form. When I try to delete a datagrid row from one of the MDI children forms, I use a MessageBox YesNo confirmation, which, after confirmed, minimizes the MDI form. Why is this happening and how can I prevent it?

Important thing to say is, if I use just "OK" MessageBox, it DOES NOT minimize the MDI parent.

TIA
Goran
 
Looking at it more closely it looks like it is not minimized, but rather de-activated. Still, it behaves as minimized, if any other window is active.


Hi all,
I have a VB.NET windows application that uses MDI form. When I try to delete a datagrid row from one of the MDI children forms, I use a MessageBox YesNo confirmation, which, after confirmed, minimizes the MDI form. Why is this happening and how can I prevent it?

Important thing to say is, if I use just "OK" MessageBox, it DOES NOT minimize the MDI parent.

TIA
Goran
 
Looking at it more closely it looks like it is not minimized, but rather de-activated. Still, it behaves as minimized, if any other window is active.

Hi all,
I have a VB.NET windows application that uses MDI form. When I try to delete a datagrid row from one of the MDI children forms, I use a MessageBox YesNo confirmation, which, after confirmed, minimizes the MDI form. Why is this happening and how can I prevent it?

Important thing to say is, if I use just "OK" MessageBox, it DOES NOT minimize the MDI parent.

TIA
Goran

Hi Goran,

Can you post a code sample of the function that displays the message
box?

Thanks!
Mike
 
Hi Goran,

Based on my understanding, you have a DataGrid control on a form. When you
press the Delete key to delete a row from the datagrid, you use a
MessageBox to confirm the operation. The problem is that after the
MessageBox is closed, the MDI parent form is de-activated. If I'm off base,
please feel free to let me know.

Are you using VS.NET 2003 or VS 2005? I performed tests on both VS.NET 2003
and VS 2005, but didn't reproduce the problem on the both.

In my VS.NET 2003 test project, I derived the DataGrid class, and override
the IsInputKey and OnKeyDown methods in the derived DataGrid class.

Class MyDataGrid
Inherits DataGrid

' override the IsInputKey method in order to get the KeyDown event to be
raised when the user presses the Delete key
Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
Return True
End Function

Protected Overrides Sub OnKeyDown(ByVal ke As
System.Windows.Forms.KeyEventArgs)
If (ke.KeyCode = Keys.Delete) Then
If (MessageBox.Show("are you sure to delete the row?",
"delete", MessageBoxButtons.YesNo) = DialogResult.Yes) Then
MyBase.OnKeyDown(ke)
End If
Else
MyBase.OnKeyDown(ke)
End If
End Sub

End Class

Build the project and add an instance of MyDataGrid on an MDI child form.
When the program is run, I select one row in the DataGrid control and press
the Delete key. A messagebox pops up and I select 'Yes'. The messagebox is
closed and the MDI parent form regains the focus.

In my VS 2005 test project, I add a DataGridView control on an MDI child
form and handle the UserDeletingRow event of the DataGridView.

Public Sub New()
AddHandler Me.DataGridView1.UserDeletingRow, AddressOf
dataGridView1_UserDeletingRow
End Sub

Sub dataGridView1_UserDeletingRow(ByVal sender As Object, ByVal e As
DataGridViewRowCancelEventArgs)
If (MessageBox.Show("are you sure to delete the row?", "delete",
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No) Then
e.Cancel = True
End If
End Sub

When the program is run, all works fine.

Is there any difference between your code and mine? If the problem is still
not resolved, you may send me a sample project that could just reproduce
the problem. To get my actual email address, remove 'online' from my
displayed email address.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Linda (& Mike),
I haven't derived my DataGrid like you did, but used the original.
I attached ContextMenu to the datagrid. So, when the user right-clicks on the row, it has an option to delete the row. No matter what the confrmation is (Yes or No), the MDI parent de-activates. I use VS.NET 2003, and the datagrid gets the data from DataTable. Here is the subroutine I use for deletion:
----------------------------------------------------
Private Sub DeleteSource(ByVal sender As Object, ByVal e As EventArgs)
Try
If MessageBox.Show("Are you sure you want to delete selected record?", "Warning!", YesNo, Question, Button2, DefaultDesktopOnly) = Yes Then
SourceIDStr = SourceDataTableObj.Rows.Item(SelectedSourceRowInt).Item("SourceID").ToString()
End If
Me.MdiParent.Activate() <--- this line makes it work fine, but why do I have to do that???
Catch ErrObj As Exception
SetErrorMessage(ErrObj)
End Try
End Sub
----------------------------------------------------

DeleteSource is called by a context menu event handler. I will try deriving my datagrid like you did, just to see if that makes it work.

TIA
Goran
 
Hi Goran,

Thank you for your reply.

I performed a test based on your sample code but still couldn't reproduce
the problem. In my test project, I didn't add the statement
'Me.MdiParent.Activate()', and the MDI parent got focused when the
MessageBox was closed.

I think the problem may be caused by the actual code in your project. You
may have a try replacing the MessageBox with a custom form of your own to
see if the problem still exists.

If the problem is still not solved, you may send me a sample project that
could just reproduce the problem.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hi Linda,
I found out what it is, it is the "MessageBoxOptions.DefaultDesktopOnly"
portion of the message box. Once I removed that, it was fine. Anyway, thanks
for all your help.

Goran Djuranovic
 
Back
Top