I have an issue. I have a CheckBox on a GroupBox on a UserControl on a TabControl that stops responding to user events after Validation. To build this yourself, create a new windows forms project. Create a user control. On the user control, place a groupbox, and in the groupbox, insert a checkbox. Create a validation event for the usercontrol, and set e.Cancel = true after a messagebox.show() so that you see that validation was called. Then, back on the form, place a tabcontrol, and then place the created usercontrol on the first tab of the tabcontrol. In the form's load event, set focus to the usercontrol by calling the select function of the usercontrol. Run the app. Select the second tab to attempt tab to the second tab. The validation in the user control should fire, and the message box should appear. Clear the messagebox. Then, try checking the check box. It doesn't change to checked. This looks like a bug, correct. Is there a bug fix to this? I created user controls because in my main app (the descried is my little test app to confirm this bug) because I reuse these usercontrols for editing new user values in a "wizard" style editor and a tab based editor for existing user values.
I would upload my test project that produces this error, but I don't see a way to do that. Here are my code files. If someone wants my project, I will gladly e-mail it to them, but the above directions and the code should help you see what I did.
Mike
Form1.cs
using
System;using
System.Collections.Generic;using
System.ComponentModel;using
System.Data;using
System.Drawing;using
System.Text;using
System.Windows.Forms;namespace
TestTabValidation{
publicpartialclassForm1 : Form{
public Form1(){
InitializeComponent();
}
privatevoid Form1_Load(object sender, EventArgs e){
groupAndButton1.Select();
}
}
}
Form1.designer.cs
namespace
TestTabValidation{
partialclassForm1{
///<summary>/// Required designer variable.///</summary>private System.ComponentModel.IContainer components = null;///<summary>/// Clean up any resources being used.///</summary>///<param name="disposing">true if managed resources should be disposed; otherwise, false.</param>protectedoverridevoid Dispose(bool disposing){
if (disposing && (components != null)){
components.Dispose();
}
base.Dispose(disposing);}
#region
Windows Form Designer generated code///<summary>/// Required method for Designer support - do not modify/// the contents of this method with the code editor.///</summary>privatevoid InitializeComponent(){
this.tabControl1 = new System.Windows.Forms.TabControl();this.tabPage1 = new System.Windows.Forms.TabPage();this.tabPage2 = new System.Windows.Forms.TabPage();this.groupAndButton1 = new TestTabValidation.GroupAndCheckbox();this.label1 = new System.Windows.Forms.Label();this.label2 = new System.Windows.Forms.Label();this.tabControl1.SuspendLayout();this.tabPage1.SuspendLayout();this.SuspendLayout();// // tabControl1// this.tabControl1.Controls.Add(this.tabPage1);this.tabControl1.Controls.Add(this.tabPage2);this.tabControl1.Location = new System.Drawing.Point(15, 67);this.tabControl1.Name = "tabControl1";this.tabControl1.SelectedIndex = 0;this.tabControl1.Size = new System.Drawing.Size(293, 248);this.tabControl1.TabIndex = 0;// // tabPage1// this.tabPage1.Controls.Add(this.groupAndButton1);this.tabPage1.Location = new System.Drawing.Point(4, 22);this.tabPage1.Name = "tabPage1";this.tabPage1.Padding = new System.Windows.Forms.Padding(3);this.tabPage1.Size = new System.Drawing.Size(285, 222);this.tabPage1.TabIndex = 0;this.tabPage1.Text = "tabPage1";this.tabPage1.UseVisualStyleBackColor = true;// // tabPage2// this.tabPage2.Location = new System.Drawing.Point(4, 22);this.tabPage2.Name = "tabPage2";this.tabPage2.Padding = new System.Windows.Forms.Padding(3);this.tabPage2.Size = new System.Drawing.Size(285, 222);this.tabPage2.TabIndex = 1;this.tabPage2.Text = "tabPage2";this.tabPage2.UseVisualStyleBackColor = true;// // groupAndButton1// this.groupAndButton1.Dock = System.Windows.Forms.DockStyle.Fill;this.groupAndButton1.Location = new System.Drawing.Point(3, 3);this.groupAndButton1.Name = "groupAndButton1";this.groupAndButton1.Size = new System.Drawing.Size(279, 216);this.groupAndButton1.TabIndex = 0;// // label1// this.label1.AutoSize = true;this.label1.Location = new System.Drawing.Point(12, 9);this.label1.Name = "label1";this.label1.Size = new System.Drawing.Size(195, 13);this.label1.TabIndex = 1;this.label1.Text = "1) Press tabPage2 to invoke validation.";// // label2// this.label2.AutoSize = true;this.label2.Location = new System.Drawing.Point(12, 37);this.label2.Name = "label2";this.label2.Size = new System.Drawing.Size(334, 13);this.label2.TabIndex = 2;this.label2.Text = "2) After clearing the message, attempt to make checkBox1 checked.";// // Form1// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(355, 330);this.Controls.Add(this.label2);this.Controls.Add(this.label1);this.Controls.Add(this.tabControl1);this.Name = "Form1";this.Text = "Form1";this.Load += new System.EventHandler(this.Form1_Load);this.tabControl1.ResumeLayout(false);this.tabPage1.ResumeLayout(false);this.ResumeLayout(false);this.PerformLayout();}
#endregion
private System.Windows.Forms.TabControl tabControl1;private System.Windows.Forms.TabPage tabPage1;private System.Windows.Forms.TabPage tabPage2;privateGroupAndCheckbox groupAndButton1;private System.Windows.Forms.Label label1;private System.Windows.Forms.Label label2;}
}
GroupandCheckbox.cs
using
System;using
System.Collections.Generic;using
System.ComponentModel;using
System.Drawing;using
System.Data;using
System.Text;using
System.Windows.Forms;namespace
TestTabValidation{
publicpartialclassGroupAndCheckbox : UserControl{
public GroupAndCheckbox(){
InitializeComponent();
}
privatevoid GroupAndCheckbox_Validating(object sender, CancelEventArgs e){
if (!checkBox1.Checked){
MessageBox.Show("Check box not checked");e.Cancel =
true;}
}
}
}
GroupandCheckBox.designer.cs
namespace
TestTabValidation{
partialclassGroupAndCheckbox{
///<summary>/// Required designer variable.///</summary>private System.ComponentModel.IContainer components = null;///<summary>/// Clean up any resources being used.///</summary>///<param name="disposing">true if managed resources should be disposed; otherwise, false.</param>protectedoverridevoid Dispose(bool disposing){
if (disposing && (components != null)){
components.Dispose();
}
base.Dispose(disposing);}
#region
Component Designer generated code///<summary>/// Required method for Designer support - do not modify /// the contents of this method with the code editor.///</summary>privatevoid InitializeComponent(){
this.groupBox1 = new System.Windows.Forms.GroupBox();this.checkBox1 = new System.Windows.Forms.CheckBox();this.groupBox1.SuspendLayout();this.SuspendLayout();// // groupBox1// this.groupBox1.Controls.Add(this.checkBox1);this.groupBox1.Location = new System.Drawing.Point(12, 19);this.groupBox1.Name = "groupBox1";this.groupBox1.Size = new System.Drawing.Size(120, 107);this.groupBox1.TabIndex = 0;this.groupBox1.TabStop = false;this.groupBox1.Text = "groupBox1";// // checkBox1// this.checkBox1.AutoSize = true;this.checkBox1.Location = new System.Drawing.Point(16, 42);this.checkBox1.Name = "checkBox1";this.checkBox1.Size = new System.Drawing.Size(80, 17);this.checkBox1.TabIndex = 0;this.checkBox1.Text = "checkBox1";this.checkBox1.UseVisualStyleBackColor = true;// // GroupAndCheckbox// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.Controls.Add(this.groupBox1);this.Name = "GroupAndCheckbox";this.Validating += new System.ComponentModel.CancelEventHandler(this.GroupAndCheckbox_Validating);this.groupBox1.ResumeLayout(false);this.groupBox1.PerformLayout();this.ResumeLayout(false);}
#endregion
private System.Windows.Forms.GroupBox groupBox1;private System.Windows.Forms.CheckBox checkBox1;}
}