Solved

LostFocus Event Does Not Fire When Expected

Posted on 2009-04-10
6
1,145 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
CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

 
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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 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