Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As per the specified code, when I press "F5" in the 1st column, last blank row of a grid, a second form will be activated. But the problem is.. after the activation of the second form, its loosing the focus from the last row to one step up (second last row) and also focus is going to another control. I have tried in the load event of the second form Me.MdiParent = FrmMain. If I removed this code (Me.MdiParent = FrmMain), its working perfectly. I mean the focus will not be change to anywhere. But I should include this code. What I should do masters?

What I have tried:

Private Sub grdDayBook_KeyDown(ByVal Sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grdDayBook.KeyDown
If CurrentColumn = 1 Then
If e.KeyCode = Keys.F5 Then
'e.SuppressKeyPress = True
FrmAccountsSearch.MdiParent = FrmMain
FrmAccountsSearch.Text = "From Daybook"
FrmAccountsSearch.Show()
FrmAccountsSearch.Activate()
End If
End If
End Sub
Posted
Updated 28-May-16 10:00am
v2
Comments
Sergey Alexandrovich Kryukov 29-May-16 9:35am    
Not quite clear. If you activate another form, first form's control looses focus, by definition. There is only one focus on the whole desktop at a time, the keyboard focus. Probably, you mean that the focus is not restored when you activate the first form again. But the "row" cannot be focused, the whole grid view is the subject of focusing. It looks like you mess up two different concepts: focus and selection. Neither focus nor selection should shift if you simply change activation of a form if you don't touch them, but it's possible that your code does something. So, use the debugger.

Also, I would strongly recommend to avoid MDI.

—SA
Venu Gopal Mulavana Kayamkulam 30-May-16 14:57pm    
U r right.... Focus is not restoring to the previously focused control on first form, when I activate that form (first form) again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900