G
Guest
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()
MyBase.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.Item1.DropDownItems.Add(Me.ControlHost1)
Me.ToolStrip = New Windows.Forms.ToolStrip
Me.ToolStrip.Items.Add(Me.Item1)
Me.ToolStripPanel = New Windows.Forms.ToolStripPanel
Me.ToolStripPanel.Dock = DockStyle.Top
Me.ToolStripPanel.Controls.Add(Me.ToolStrip)
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
Me.Controls.Add(Me.DataInput1)
Me.Controls.Add(Me.InstructionsLabel)
Me.Controls.Add(Me.ToolStripPanel)
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()
MyBase.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
Me.Controls.Add(Me.TextBox)
Me.Controls.Add(Me.Button)
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
System.ComponentModel.CancelEventArgs)
MessageBox.Show(System.String.Format("Validating {0}", Me.Name))
End Sub
Private Sub TextBox_Validated(ByVal sender As Object, ByVal e As
System.EventArgs)
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!
Lance
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()
MyBase.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.Item1.DropDownItems.Add(Me.ControlHost1)
Me.ToolStrip = New Windows.Forms.ToolStrip
Me.ToolStrip.Items.Add(Me.Item1)
Me.ToolStripPanel = New Windows.Forms.ToolStripPanel
Me.ToolStripPanel.Dock = DockStyle.Top
Me.ToolStripPanel.Controls.Add(Me.ToolStrip)
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
Me.Controls.Add(Me.DataInput1)
Me.Controls.Add(Me.InstructionsLabel)
Me.Controls.Add(Me.ToolStripPanel)
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()
MyBase.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
Me.Controls.Add(Me.TextBox)
Me.Controls.Add(Me.Button)
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
System.ComponentModel.CancelEventArgs)
MessageBox.Show(System.String.Format("Validating {0}", Me.Name))
End Sub
Private Sub TextBox_Validated(ByVal sender As Object, ByVal e As
System.EventArgs)
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!
Lance