473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Textbox Events

I have a simple form with one button and one text box. In the Form, I create
an array list to track the events by adding a descriptive string item to the
arraylist in each event. I first Click on the Button then Click on the
TextBox and enter an "a" then click on the Button again. The following is
what I get for the event tracking Arraylist:

but - GotFocus
but - Clicked
but - LostFocus
txt - Changed
but - GotFocus
but - Clicked

No where do I get the events Textbox.GotFocus or TextBox.LostFocus or
TextBox.Validating or TextBox.Validated firing. Note that the
TextBox.CauseValidation is set to True at Design time.

--
Dennis in Houston
Nov 21 '05 #1
10 3077
Hi,

The validating event is fired when the control you are moving to has
it causes validation property set to true. I have in the past deleted a
control and readded it. I found the code in the existing event handlers for
the old control did not work. I had to add a new event handler and copy the
code from the old event handler. Maybe this will help.

Ken
---------------
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
I have a simple form with one button and one text box. In the Form, I
create
an array list to track the events by adding a descriptive string item to the
arraylist in each event. I first Click on the Button then Click on the
TextBox and enter an "a" then click on the Button again. The following is
what I get for the event tracking Arraylist:

but - GotFocus
but - Clicked
but - LostFocus
txt - Changed
but - GotFocus
but - Clicked

No where do I get the events Textbox.GotFocus or TextBox.LostFocus or
TextBox.Validating or TextBox.Validated firing. Note that the
TextBox.CauseValidation is set to True at Design time.

--
Dennis in Houston
Nov 21 '05 #2
Ken,

Txt.changed is fired is in Dennis text. However your answer could have been
true.

Cor
Nov 21 '05 #3
Dennis,

I tried this,
I put a textbox and a button on a form
I pasted in this code
Than I run the code, and typed in "Dennis" in the textbox. Than it showed
"Hello Dennis".
How do you catch those events, probably is there the problem.

\\\
Private Sub TextBox1_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles TextBox1.Validating
MessageBox.Show("Hello " & TextBox1.Text)
End Sub
///

I hope this helps?

Cor
Nov 21 '05 #4
Cor, in each event, I add an item to my tracking arraylist like so:

Private Sub TextBox1_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles TextBox1.Validating
TrackingArray.Add("txt - Validating")
End Sub

I then have an event on the form that when it is clicked, the program breaks
and I print out the TrackingArray. This gives me a history of what was fired
in what sequence. Note that I also tried adding a message box like you did
and got nothing. Did you check if the gotfocus and lost focus events are
firing? Mine don't. Any idea what the problem is? It's a simple form and
it's really annoying that it doesn't work and follow M'soft's documentation
on what should fire. I know the text box changed event fires but why not the
others?

"Cor Ligthert" wrote:
Dennis,

I tried this,
I put a textbox and a button on a form
I pasted in this code
Than I run the code, and typed in "Dennis" in the textbox. Than it showed
"Hello Dennis".
How do you catch those events, probably is there the problem.

\\\
Private Sub TextBox1_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles TextBox1.Validating
MessageBox.Show("Hello " & TextBox1.Text)
End Sub
///

I hope this helps?

Cor

Nov 21 '05 #5
Here's my code and it's in a separate project with only the form with one
button and one text box...very simple.

dim ev as arraylist = new arraylist

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ev.Add("but - Click")
End Sub

Private Sub TextBox1_GotFocus(ByVal sender As System.Object, ByVal e As
System.EventArgs)
ev.Add("text - gotfocus")
End Sub

Private Sub TextBox1_Validating(ByVal sender As System.Object, ByVal e As
System.ComponentModel.CancelEventArgs)
ev.Add("text - Validating")
MsgBox("Tracking", MsgBoxStyle.OKOnly, "I'm in Validating")
End Sub

Private Sub TextBox1_LostFocus(ByVal sender As System.Object, ByVal e As
System.EventArgs)
ev.Add("Text - LostFocus")
End Sub

Private Sub Button_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.GotFocus
ev.Add("but - GotFocus")
End Sub

Private Sub Button_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.LostFocus
ev.Add("but - LostFocus")
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged
ev.Add("text - Changed")
End Sub

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
Dim i As Integer = 0 'Have a Break set on this line then view ev in
the command editor.
End Sub
End Class

"Cor Ligthert" wrote:
Dennis,

I tried this,
I put a textbox and a button on a form
I pasted in this code
Than I run the code, and typed in "Dennis" in the textbox. Than it showed
"Hello Dennis".
How do you catch those events, probably is there the problem.

\\\
Private Sub TextBox1_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles TextBox1.Validating
MessageBox.Show("Hello " & TextBox1.Text)
End Sub
///

I hope this helps?

Cor

Nov 21 '05 #6
Dennis,

Do you see that in this code is your code is almost what Ken wrote.

However the strange thing is that you have a handler with the
textbox.textbox changed, and that was in your result text.

So probably you deleted the textbox once. Added it again and did than add
afterwards as well the handler for the textchanged.

Are you trying to confuse us

:-)

no problem I hope this helps

Cor
Nov 21 '05 #7
Ken,

See my last message to Dennis.

Your answer was right,

However it was probably a little bit confusing what Dennis did.

Cor
Nov 21 '05 #8
I am not trying to confuse anyone. I did not delete the text box at any
time. For the sake of argument, I tried it again exactly as I did it the
first time. I started a new project then added a button1 and text box and the
public variable "eventtracker as an arraylist. This time it seemed to track
all the events ok. However, the textbox1.LostFocus event fired before the
textbox1.Validating event which is contrary to the M'soft's documentation
which says the validating event fires before the lostfocus event. This
eratic behavior of the control events makes if difficult and seems to be
inexcusable on Microsoft's part. Here is the complete project code:

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub _
InitializeComponent ()
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(184, 146)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(76, 24)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(184, 62)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(84, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 262)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Public eventtracker As ArrayList = New ArrayList

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles TextBox1.GotFocus
eventtracker.Add("textbox1 - gotfocus")
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles TextBox1.TextChanged
eventtracker.Add("textbox1 - TextChanged")
End Sub

Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles TextBox1.Leave
eventtracker.Add("textbox1 - Leave")
End Sub

Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles TextBox1.LostFocus
eventtracker.Add("textbox1 - Lostfocus")
End Sub
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As _
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
eventtracker.Add("textbox1 - Validating")
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles Button1.Click
eventtracker.Add("button1 - Click")
End Sub
Private Sub Button1_GotFocus(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles Button1.GotFocus
eventtracker.Add("button1 - gotfocus")
End Sub

Private Sub Button1_LostFocus(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles Button1.LostFocus
eventtracker.Add("button1 - lostfocus")
End Sub

Private Sub Form1_Click(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles MyBase.Click
Dim s As String
Dim i As Integer
While i < eventtracker.Count
s = s & eventtracker(i).ToString & vbLf
i = i + 1
End While
MsgBox(s, MsgBoxStyle.OKOnly, "Event Track...")

End Sub
End Class

"Cor Ligthert" wrote:
Dennis,

Do you see that in this code is your code is almost what Ken wrote.

However the strange thing is that you have a handler with the
textbox.textbox changed, and that was in your result text.

So probably you deleted the textbox once. Added it again and did than add
afterwards as well the handler for the textchanged.

Are you trying to confuse us

:-)

no problem I hope this helps

Cor

Nov 21 '05 #9
I see what happened now. The handles xxxx.xx somehow got removed from the
sub statement. I did not delete the text box and have no idea how they got
removed. Still, the TextBox lostfocus event fires before the Validating
event.

"Cor Ligthert" wrote:
Dennis,

Do you see that in this code is your code is almost what Ken wrote.

However the strange thing is that you have a handler with the
textbox.textbox changed, and that was in your result text.

So probably you deleted the textbox once. Added it again and did than add
afterwards as well the handler for the textchanged.

Are you trying to confuse us

:-)

no problem I hope this helps

Cor

Nov 21 '05 #10
Dennis,

It is not easy to find, however AFAIK those events fire in two different
sequences.

Maybe you can look for it yourself on MSDN.

I thought that Peter Huang, Jeffrey Tan or a collegue of those once has sent
a message about this to this newsgroup.

Cor
Nov 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jonas L | last post by:
Hi, I need to create a textbox which acts as a normal textbox but with the following extra requirements: 1) In-focus color, when the textbox gets focus the backcolor property of the textbox...
7
by: Seash | last post by:
Hi friends , here is the sample code private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if(e.KeyChar == 13) //enter { txtbox2.Focus(); }
28
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I...
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
8
by: John | last post by:
Hi, I am developing an application using VB.Net and hope that the textbox can process features which are similar to auto-complete features in Window. For example, when user types "ap" in a...
2
by: Jonathan Allen | last post by:
In dialog boxes in Windows, the text in TextBox is automatically selected if you tab into the TextBox , but not when you select the TextBox using the mouse. What is the preferred way to support...
8
by: Filipe Marcelino | last post by:
Hi, I'm trying to create a textbox inheriting from the standard textbox. I would like to: 1. repaint the textbox border; 2. define a color for that border; Till now I made this:
5
by: =?Utf-8?B?QmVuIFIu?= | last post by:
Hi, In a .NET 2.0 winforms application, I've got a textbox that, when updated, uses the validated event to cascade the change to another textbox (along with another value). This works well if...
1
by: JFKJr | last post by:
Hello everyone, the following Access VBA code opens an excel file and creates textboxes in a given range of cells dynamically. The code attaches "MouseUP" and "Exit" events to the textboxes (using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.