Solved

LostFocus Event Does Not Fire When Expected

Posted on 2009-04-10
6
1,118 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
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:bmatumbura
Comment Utility
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
Comment Utility
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
Comment Utility
Can you try the code I posted above and see if it works in your environment?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Author Comment

by:brian_appliedcpu
Comment Utility
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
Comment Utility
Sure, you may have to try that
0
 
LVL 2

Accepted Solution

by:
brian_appliedcpu earned 0 total points
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now