Solved

LostFocus Event Does Not Fire When Expected

Posted on 2009-04-10
6
1,136 Views
Last Modified: 2013-11-26
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
Comment
Question by:brian_appliedcpu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:bmatumbura
ID: 24115577
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
 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 24116212
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
 
LVL 11

Expert Comment

by:bmatumbura
ID: 24116310
Can you try the code I posted above and see if it works in your environment?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 24116432
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
 
LVL 11

Assisted Solution

by:bmatumbura
bmatumbura earned 500 total points
ID: 24116503
Sure, you may have to try that
0
 
LVL 2

Accepted Solution

by:
brian_appliedcpu earned 0 total points
ID: 24116908
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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question