469,945 Members | 2,254 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

ActiveX ruins Validation events.

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

// 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)
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
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();
// 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.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.a xUserControl11)).EndInit();


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

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


private void button1_Click(object sender, System.EventArgs e)
Does any one know how to overcome this bug?

Thanks ,
Dan & Zeev.

Nov 17 '05 #1
0 1177

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by AIM48 | last post: by
5 posts views Thread by Richard Brown | last post: by
23 posts views Thread by Galen Somerville | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.