|
-
Jul 2nd, 2008, 10:52 AM
#1
Thread Starter
Addicted Member
[RESOLVED] [2008] DataGridView focus problem
Hi,
I've got a DataGridView which isn't receiving the focus.
I've got a bound DataGridView, and bound TextBoxes, so when the user scrolls through the grid, the text boxes display data associated with whatever is selected in the grid.
The user can press "U" (to update) the data, and a TabControl containing the text boxes becomes enabled so the user can make some changes.
What I'm finding is that if the user abandons the changes (where all the TextBoxes, Combo's revert back to their original state), I can't put the focus back to the DataGridView UNLESS I put a messagebox in (perhaps saying "Changes abandoned" - which might be ok, anyway).
If I don't put the message box in, the focus moves to the menus.
Its as if delaying the DataGridView.Focus, via the messagebox, allows the .Focus to work.
-
Jul 2nd, 2008, 12:16 PM
#2
Re: [2008] DataGridView focus problem

Show us the code surrounding the .Focus method.
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Jul 2nd, 2008, 03:11 PM
#3
Thread Starter
Addicted Member
Re: [2008] DataGridView focus problem
This works, but if I comment out the MessageBox, the focus isn't set to dgv.
Code:
Private Sub TextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ....
If e.KeyCode = Keys.F10 Then
bind.CancelEdit()
Me.TabControl1.Enabled = False
Me.dgv.Enabled = True
Me.dgv.Focus()
MessageBox.Show("Changes have been abandoned", "Abort", MessageBoxButtons.OK, MessageBoxIcon.Information)
-
Jul 2nd, 2008, 03:20 PM
#4
Re: [2008] DataGridView focus problem
Have you tried commenting out the msgbox line and stepping through the code after the call to dgv.focus? I'm just curious as to whether it's hitting some other event code somewhere else in the app.
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Jul 2nd, 2008, 03:27 PM
#5
Thread Starter
Addicted Member
Re: [2008] DataGridView focus problem
I didn't try that, but I'm glad I did now!
REALLY bizarre. I break on .Focus, and stepping through shows that it does everything that it should through the end of the sub. If I continue as normal when the sub has been processed, I go back to the form, and the dgv has the focus!!!
-
Jul 2nd, 2008, 03:38 PM
#6
Re: [2008] DataGridView focus problem
I wonder if an application.doevents in the place of the msgbox will help?
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Jul 2nd, 2008, 03:46 PM
#7
Thread Starter
Addicted Member
Re: [2008] DataGridView focus problem
Errmmm, yes, this works.
Now that was strange!
Many thanks for the suggestion!
-
Jul 2nd, 2008, 03:50 PM
#8
Re: [2008] DataGridView focus problem
No prob. And I agree fully... it's wierd. I suspect this isn't the 'best' solution, but hey, it works.
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|