472,805 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Validating issue with ToolStripDropDown

I've noticed that controls do not raise a Validating event if they are
contained in a ToolStripDropDown via a ToolStripControlHost item. Please run
the following sample and follow the instructions on the form to reproduce
this issue:


Public Class Form1
Inherits Windows.Forms.Form

Public ToolStripPanel As Windows.Forms.ToolStripPanel
Public ToolStrip As Windows.Forms.ToolStrip
Public Item1 As Windows.Forms.ToolStripMenuItem
Public ControlHost1 As Windows.Forms.ToolStripControlHost

Public InstructionsLabel As Windows.Forms.Label

Public DataInput1 As DataInput
Public DataInput2 As DataInput

Public Sub New()

Me.Size = New Drawing.Size(400, 300)

Me.DataInput1 = New DataInput
Me.DataInput1.Name = "DataInput1"
Me.DataInput1.Dock = DockStyle.Fill
Me.DataInput1.Button.Text = "Button1"

Me.DataInput2 = New DataInput
Me.DataInput2.Name = "DataInput2"
Me.DataInput2.Dock = DockStyle.Fill
Me.DataInput2.Button.Text = "Button2"

Me.ControlHost1 = New Windows.Forms.ToolStripControlHost(Me.DataInput2)

Me.Item1 = New Windows.Forms.ToolStripMenuItem("Item")

Me.ToolStrip = New Windows.Forms.ToolStrip

Me.ToolStripPanel = New Windows.Forms.ToolStripPanel
Me.ToolStripPanel.Dock = DockStyle.Top

Me.InstructionsLabel = New Windows.Forms.Label
Me.InstructionsLabel.Text = "Click inside of the TextBox on this form,
then click Button1. Notice that the Validating event is raised. Now, click
the ToolStrip item to show its DropDown. Next, click inside of the
DropDown's TextBox and then click Button2. Notice that the Validating event
for the DropDown's TextBox is not raised."
Me.InstructionsLabel.Height = 128
Me.InstructionsLabel.Dock = DockStyle.Bottom

End Sub

End Class

Public Class DataInput
Inherits Windows.Forms.Panel

Public TextBox As Windows.Forms.TextBox
Public Button As Windows.Forms.Button

Public Overrides Function GetPreferredSize(ByVal proposedSize As
System.Drawing.Size) As System.Drawing.Size
Dim width As Integer = Me.TextBox.Width
Dim height As Integer = (Me.TextBox.Height + Me.Button.Height)
Return New Drawing.Size(width, height)
End Function

Public Sub New()

Me.TextBox = New Windows.Forms.TextBox

Me.Button = New Windows.Forms.Button
Me.Button.Width = Me.TextBox.Width
Me.Button.Top = Me.TextBox.Bottom


AddHandler Me.TextBox.Validating, AddressOf Me.TextBox_Validating
AddHandler Me.TextBox.Validated, AddressOf Me.TextBox_Validated

Me.Size = Me.GetPreferredSize(Drawing.Size.Empty)
End Sub

Private Sub TextBox_Validating(ByVal sender As Object, ByVal e As
MessageBox.Show(System.String.Format("Validating {0}", Me.Name))
End Sub

Private Sub TextBox_Validated(ByVal sender As Object, ByVal e As
MessageBox.Show(System.String.Format("Validated {0}", Me.Name))
End Sub

End Class


Is this a known issue and, more importantly, are there any workarounds?

Thanks for any help!

Aug 22 '07 #1
1 3726
Hi Lance,

Yes, I can reproduce your problem with the code snippet you provided.

Actually, this is has been reported before due to the behavior of
ToolStrip. Internally, the Validating event is fired during the focus
change between controls. The design rational for ToolStrip is that it will
not grab focus from the controls on the form. If we click textbox or button
in ToolStrip, it will not steal focus from the original control, so no
validating is triggered. For details, please refer to the original reported
issue in the link below:
"Control validation events not fired when toolstrip button is clicked"

However, your scenairo is more complex than the customer in above link,
since you wanted to perform validating over the TextBox in the ToolStrip.
Since the TextBox in the ToolStrip never got focus, calling Form.Validate()
method as suggested in the above link will not work correctly.

I have tried to set the focus programatically to the TextBox in the
ToolStrip, however, it does not work either. Without setting the focus onto
the TextBox, there is no single place(LostFocus) to perform validating, so
I do not think there is any perfect workaround for your scenario. The only
workaround I can think of is calling the TextBox_Validating and
TextBox_Validated methods in all the places you may go away after finished
editing in ToolStrip TextBox. For example, you have to call these 2 methods
in Button2.Click event handler like below:

AddHandler Me.DataInput2.Button.Click, AddressOf Button2_Click
Private Sub Button2_Click(ByVal sender As Object, ByVal e As
Me.DataInput2.TextBox_Validating(Me.DataInput2, New
Me.DataInput2.TextBox_Validated(Me.DataInput2, New EventArgs())
End Sub

Public Sub TextBox_Validating(ByVal sender As Object, ByVal e As
MessageBox.Show(System.String.Format("Validating {0}", Me.Name))
End Sub

Public Sub TextBox_Validated(ByVal sender As Object, ByVal e As
MessageBox.Show(System.String.Format("Validated {0}", Me.Name))
End Sub

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
Get notification to my posts through email? Please refer to

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 23 '07 #2

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

Similar topics

by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
by: Bradley Bossard via DotNetMonster.com | last post by:
I am having an issue with the .NET framework (or C#) and validating events. I have implemented several validating event handlers for textboxes on a form. When I run the app, the form works...
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have written a simple validating event for a couple of textbox's on a form. They validate just fine when leaving the form, now for the problem. If i click a button to begin execution, i...
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
by: Matt Spinder | last post by:
Can I create a ToolStripDropDown that overflows to a second column instead of scrolling?
by: josh | last post by:
Hi, I am trying to validate cXML documents against cXML.dtd using the XmlValidatingReader. If I set the XMLValidatingReader's ValidatingType to ValidationType.DTD, I get the following...
by: Ben R. | last post by:
Hi, I have a ToolStripDropDownButton and would like to databind a list of menuitems for its associated ToolStripDropDown object. Is this possible? The ToolStripDropDown class doesn't have a...
by: MP | last post by:
Hi all, I have: ToolStripDropDown control with Label, TextBox and two Button controls inside it. When TextBox has the focus and I press right Alt key then ToolStripDropDown is closed in the...
by: Peted | last post by:
Hi if i derive a reference to a control on a winform (ie Control activeControl = somecontrol on the form) how can i test if that control has a validating or validated event and more importantly...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.