Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1198
  • Last Modified:

LostFocus Event Does Not Fire When Expected

I have a WinForm with a treeview control and 5 panel controls. All panels are non-visible at runtime. Based on the treeview node selected, the associated panel becomes visible. On one of the panels, there are several textbox controls and maskedtextbox controls. Each textbox control has a LostFocus event. When the user navigates away from Textbox1, the LostFocus is fired, as I would expect. But when the user navigates away from Textbox2, the LostFocus does not fire; if you click back on Textbox2, then the LostFocus fires. This happens with all the textbox controls, except Textbox1. I don't know what to make of this.

For Textbox2, if I switch to the Leave or Validating events, I have the same problem. Any ideas out there?
0
brian_appliedcpu
Asked:
brian_appliedcpu
  • 3
  • 3
2 Solutions
 
bmatumburaCommented:
What version of VB.NET are you using? What's the service pack level?

I have tried it on VB.NET 2008 and it seems to work fine.


' Place 4 TextBoxes on a form then copy and replace the form's code with the one below
Public Class Form1
 
  Private Sub TextBox1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Leave, TextBox2.Leave, TextBox3.Leave, TextBox4.Leave
    MsgBox(CType(sender, TextBox).Name + " lost focus")
  End Sub
End Class

Open in new window

0
 
brian_appliedcpuAuthor Commented:
I am using:
 * Microsoft Visual Studio 2005 Professional Edition version 8.0.50727.762  (SP.050727-7600) ENU Service Pack 1 (KB926601)
 * Microsoft .NET Framework version 2.0.50727 SP2
 * Microsoft Visual Basic 2005   77626-009-2097021-41615
I guess I'll try another test form and see what happens with it.
0
 
bmatumburaCommented:
Can you try the code I posted above and see if it works in your environment?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
brian_appliedcpuAuthor Commented:
I created a new WinForm from scratch, dropped a Panel control onto the from, added 3 new MaskedTextbox controls onto the Panel, assigned LostFocus events to each ot the textbox controls, and it works fine. The only thing I'm doing differently in this new WinForm (as opposed to my original WinForm) is that I do not have multiple Panel controls that are being set visible/non-visible based on the selection of a treeview control.

I think I'm going to go back to the original form, remove all the textbox controls, and rebuild them from scratch, and see if that resolves the problem.
0
 
bmatumburaCommented:
Sure, you may have to try that
0
 
brian_appliedcpuAuthor Commented:
Deleted all the code behind the textbox controls, deleted the controls themselves from the original WinForm, added new controls back onto the form, entered the necessary LostFocus events, and all is good (except for the development time that was lost).
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now