Solved

LostFocus Event Does Not Fire When Expected

Posted on 2009-04-10
6
1,128 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

820 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