[Mono-bugs] [Bug 329714] ErrorProvider: NRE in ErrorProvider+ErrorProperty.window_Tick

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Oct 8 10:05:31 EDT 2007


https://bugzilla.novell.com/show_bug.cgi?id=329714#c1





--- Comment #1 from Andy Hume <andyhume32 at yahoo.co.uk>  2007-10-08 08:05:31 MST ---
OK, found a simple repro:
[[
using System;
using System.Windows.Forms;

class ErrorProviderNotAddSetCC : Form
{
    static void Main(string[] args)
    {
        Application.Run(new ErrorProviderNotAddSetCC());
    }

    ErrorProviderNotAddSetCC()
    {
        TextBox tb = new TextBox();
        //
        ErrorProvider ep = new ErrorProvider();
        ep.SetIconAlignment(tb, ErrorIconAlignment.MiddleRight);
        ep.SetIconPadding(tb, 2);
        //
        ep.ContainerControl = this;
        //
        this.Controls.Add(tb);
        //
        //
        ep.SetError(tb, "arggggh");
    }
}
]]

The case is, create the textbox (etc), set the ErrorProvider for it, set the
EP's ContainerControl, and lastly add the textbox to the form.  This causes the
ErrorWindow.parent to be unset both at initialization and not set -- when it
normally is in event control_ParentChanged -- because of the ContainerControl
setting.  This is the format of code that the VS Form Designer creates.


*A* hack(?) fix is the below:
[[
Index:
D:/cygwin/usr/src/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ErrorProvider.cs
===================================================================
---
D:/cygwin/usr/src/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ErrorProvider.cs
       (revision 87029)
+++
D:/cygwin/usr/src/mono/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ErrorProvider.cs
       (working copy)
@@ -255,7 +255,7 @@

        private void control_ParentChanged (object sender, EventArgs e)
        {
-               if (ep.container != null)
+               if (ep.container != null && window.Parent != null)
                        return;
                control.Parent.Controls.Add (window);
                control.Parent.Controls.SetChildIndex (window, 0);
]]


However should set_ContainerControl also(?) do *something* like the following:
[[
   foreach (ErrorProperty ep in controls.Values) {
      container.Controls.Add(ep.window);
      container.Controls.SetChildIndex(ep.window, 0);
   }
]]

Don't know what set_ContainerControl's intended for?  Maybe it is meant to
override any parent setting(s) implied from attaching to the extended controls.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list