By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,677 Members | 1,218 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,677 IT Pros & Developers. It's quick & easy.

ActiveX ruins Validation events.

P: n/a
I am using an ActiveX control in a .NET application which I put on a
form. I have another .NET control on that form that handles the
Validating event. The method that handles the Validating event, shows a
message box and sets e.Cancel = True. When I click any other control in
the form, the message box shows and the focus returns to the control
that handled the Validating event. The problem happens when I click on
the ActiveX control. The ActiveX control gets the focus and the focus
doesn't return to the validated control and no message box is
displayed. With a different ActiveX control the message was displayed,
but the focus didn't return to the validated control.

I reproduced the bug in a small application. In that application I
wrote an ActiveX in VB 6 that has an edit box. In a c# .NET application
I put on a form the ActiveX and 2 text boxes. One text box is validated
and is called textBoxValidated and the other one is not vaildated and
is called textBoxRegular (the regular text box is used to demonstrate
regular validating behaviour) . In this form, the first time you click
on the ActiveX, it works ok, but the 2nd time it doens't work ok
Here is the code of the form:

"
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication5
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private AxProject1.AxUserControl1 axUserControl11;
private System.Windows.Forms.TextBox textBoxValidated;
private System.Windows.Forms.TextBox textBoxRegular;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));
this.textBoxValidated = new System.Windows.Forms.TextBox();
this.axUserControl11 = new AxProject1.AxUserControl1();
this.textBoxRegular = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.a xUserControl11)).BeginInit();
this.SuspendLayout();
//
// textBoxValidated
//
this.textBoxValidated.Location = new System.Drawing.Point(448, 72);
this.textBoxValidated.Name = "textBoxValidated";
this.textBoxValidated.TabIndex = 2;
this.textBoxValidated.Text = "validated text box";
this.textBoxValidated.Validating += new
System.ComponentModel.CancelEventHandler(this.text Box1_Validating);
//
// axUserControl11
//
this.axUserControl11.Enabled = true;
this.axUserControl11.Location = new System.Drawing.Point(128, 160);
this.axUserControl11.Name = "axUserControl11";
this.axUserControl11.OcxState =
((System.Windows.Forms.AxHost.State)(resources.Get Object("axUserControl11.OcxState")));
this.axUserControl11.Size = new System.Drawing.Size(320, 240);
this.axUserControl11.TabIndex = 3;
//
// textBoxRegular
//
this.textBoxRegular.Location = new System.Drawing.Point(544, 152);
this.textBoxRegular.Name = "textBoxRegular";
this.textBoxRegular.Size = new System.Drawing.Size(88, 20);
this.textBoxRegular.TabIndex = 4;
this.textBoxRegular.Text = "Regular text box";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(824, 470);
this.Controls.Add(this.textBoxRegular);
this.Controls.Add(this.axUserControl11);
this.Controls.Add(this.textBoxValidated);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.a xUserControl11)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void textBox1_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{

MessageBox.Show("DAN:(");
e.Cancel=true;
}

private void button1_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
"
Does any one know how to overcome this bug?

Thanks ,
Dan & Zeev.

Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.