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.