Hi,
I have a problem on the CausesValidation between Main Form and Child Form.
In the Main Form (midChildContainer form), I have a commandbar control with 2 buttons. When those buttons are clicked, a function in Child Form will be involved.
However, I want the validating event in the child form to be triggered when the first button in Main Form is clicked. When, the other button is clicked, the validating event should not be fired.
I tried to set the causesvalidation in CommandBar to False. Then, whatever buttons is clicked, the validating event never fire.
Is there any way to do? Thanks!
The following is the code:
Main Form Designer:
Main Form Code:
Child Form Designer:
Child Form Code:
Emily
I have a problem on the CausesValidation between Main Form and Child Form.
In the Main Form (midChildContainer form), I have a commandbar control with 2 buttons. When those buttons are clicked, a function in Child Form will be involved.
However, I want the validating event in the child form to be triggered when the first button in Main Form is clicked. When, the other button is clicked, the validating event should not be fired.
I tried to set the causesvalidation in CommandBar to False. Then, whatever buttons is clicked, the validating event never fire.
Is there any way to do? Thanks!
The following is the code:
Main Form Designer:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _Partial Class FrmMainMenu Inherits Telerik.WinControls.UI.RadForm 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) End Try 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. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.RadCommandBar1 = New Telerik.WinControls.UI.RadCommandBar() Me.CommandBarRowElement1 = New Telerik.WinControls.UI.CommandBarRowElement() Me.CommandBarStripElement1 = New Telerik.WinControls.UI.CommandBarStripElement() Me.cmdButton = New Telerik.WinControls.UI.CommandBarButton() Me.cmdButton2 = New Telerik.WinControls.UI.CommandBarButton() CType(Me.RadCommandBar1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'RadCommandBar1 ' Me.RadCommandBar1.AutoSize = True Me.RadCommandBar1.CausesValidation = False Me.RadCommandBar1.Dock = System.Windows.Forms.DockStyle.Top Me.RadCommandBar1.Location = New System.Drawing.Point(0, 0) Me.RadCommandBar1.Name = "RadCommandBar1" Me.RadCommandBar1.Rows.AddRange(New Telerik.WinControls.UI.CommandBarRowElement() {Me.CommandBarRowElement1}) Me.RadCommandBar1.Size = New System.Drawing.Size(579, 55) Me.RadCommandBar1.TabIndex = 1 Me.RadCommandBar1.Text = "Without Validation" ' 'CommandBarRowElement1 ' Me.CommandBarRowElement1.DisplayName = Nothing Me.CommandBarRowElement1.MinSize = New System.Drawing.Size(25, 25) Me.CommandBarRowElement1.Strips.AddRange(New Telerik.WinControls.UI.CommandBarStripElement() {Me.CommandBarStripElement1}) ' 'CommandBarStripElement1 ' Me.CommandBarStripElement1.DisplayName = "CommandBarStripElement1" Me.CommandBarStripElement1.FloatingForm = Nothing Me.CommandBarStripElement1.Items.AddRange(New Telerik.WinControls.UI.RadCommandBarBaseItem() {Me.cmdButton, Me.cmdButton2}) Me.CommandBarStripElement1.Name = "CommandBarStripElement1" Me.CommandBarStripElement1.Text = "" ' 'cmdButton ' Me.cmdButton.AccessibleDescription = "CommandBarButton1" Me.cmdButton.AccessibleName = "CommandBarButton1" Me.cmdButton.CanFocus = False Me.cmdButton.DisplayName = "Without Validation" Me.cmdButton.DrawText = True Me.cmdButton.Image = Nothing Me.cmdButton.ImageAlignment = System.Drawing.ContentAlignment.BottomRight Me.cmdButton.KeyTip = "WITHOUT VALIDATION" Me.cmdButton.Name = "cmdButton" Me.cmdButton.Text = "Without Validation" Me.cmdButton.TextImageRelation = System.Windows.Forms.TextImageRelation.TextAboveImage Me.cmdButton.Visibility = Telerik.WinControls.ElementVisibility.Visible Me.cmdButton.VisibleInOverflowMenu = True ' 'cmdButton2 ' Me.cmdButton2.AccessibleDescription = "With Validation" Me.cmdButton2.AccessibleName = "With Validation" Me.cmdButton2.CanFocus = False Me.cmdButton2.DisplayName = "CommandBarButton1" Me.cmdButton2.DrawText = True Me.cmdButton2.Image = Nothing Me.cmdButton2.Name = "cmdButton2" Me.cmdButton2.Text = "With Validation" Me.cmdButton2.Visibility = Telerik.WinControls.ElementVisibility.Visible Me.cmdButton2.VisibleInOverflowMenu = True ' 'FrmMainMenu ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(579, 579) Me.Controls.Add(Me.RadCommandBar1) Me.IsMdiContainer = True Me.Name = "FrmMainMenu" ' ' ' Me.RootElement.ApplyShapeToControl = True Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "FrmMainMenu" Me.WindowState = System.Windows.Forms.FormWindowState.Maximized CType(Me.RadCommandBar1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents RadCommandBar1 As Telerik.WinControls.UI.RadCommandBar Friend WithEvents CommandBarRowElement1 As Telerik.WinControls.UI.CommandBarRowElement Friend WithEvents CommandBarStripElement1 As Telerik.WinControls.UI.CommandBarStripElement Friend WithEvents cmdButton As Telerik.WinControls.UI.CommandBarButton Friend WithEvents cmdButton2 As Telerik.WinControls.UI.CommandBarButtonEnd ClassMain Form Code:
Public Class FrmMainMenu Private frmChild As FrmChild Private currentForm As Object Private Sub FrmMainMenu_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load frmChild = New FrmChild frmChild.Top = 0 frmChild.Left = 0 frmChild.MdiParent = Me frmChild.Show() End Sub Private Sub cmdButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdButton.Click currentForm = Me.ActiveMdiChild currentForm.WithoutValidationClick() End Sub Private Sub cmdButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdButton2.Click currentForm = Me.ActiveMdiChild currentForm.WithValidationClick() End Sub Private Sub cmdButton2_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdButton2.MouseHover RadCommandBar1.CausesValidation = True End Sub Private Sub cmdButton2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdButton2.MouseLeave RadCommandBar1.CausesValidation = False End SubEnd ClassChild Form Designer:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _Partial Class FrmChild Inherits Telerik.WinControls.UI.RadForm 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) End Try 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. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.RadTextBox1 = New Telerik.WinControls.UI.RadTextBox() Me.RadLabel1 = New Telerik.WinControls.UI.RadLabel() CType(Me.RadTextBox1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.RadLabel1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'RadTextBox1 ' Me.RadTextBox1.Location = New System.Drawing.Point(13, 36) Me.RadTextBox1.Name = "RadTextBox1" Me.RadTextBox1.Size = New System.Drawing.Size(198, 20) Me.RadTextBox1.TabIndex = 0 Me.RadTextBox1.TabStop = False Me.RadTextBox1.Text = "123" ' 'RadLabel1 ' Me.RadLabel1.Location = New System.Drawing.Point(13, 12) Me.RadLabel1.Name = "RadLabel1" Me.RadLabel1.Size = New System.Drawing.Size(153, 18) Me.RadLabel1.TabIndex = 1 Me.RadLabel1.Text = "Only ABC is an validate input." ' 'FrmChild ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.CausesValidation = False Me.ClientSize = New System.Drawing.Size(293, 82) Me.Controls.Add(Me.RadTextBox1) Me.Controls.Add(Me.RadLabel1) Me.Name = "FrmChild" ' ' ' Me.RootElement.ApplyShapeToControl = True Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual Me.Text = "FrmChild" CType(Me.RadTextBox1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.RadLabel1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents RadTextBox1 As Telerik.WinControls.UI.RadTextBox Friend WithEvents RadLabel1 As Telerik.WinControls.UI.RadLabelEnd ClassChild Form Code:
Public Class FrmChild Private oParent As Object Public Sub WithoutValidationClick() MessageBox.Show("Without Validation Click from Main Menu.") End Sub Public Sub WithValidationClick() MessageBox.Show("With Validation Click from Main Menu.") End Sub Private Sub RadTextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles RadTextBox1.Validating If RadTextBox1.Text <> "ABC" Then MessageBox.Show("Invalid input.") End If End Sub Private Sub FrmChild_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load oParent = Me.MdiParent End SubEnd ClassEmily