[Mono-bugs] [Bug 664828] New: Data binding pull should only happens if control XXXChanged event has fired

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Jan 16 16:45:33 EST 2011


https://bugzilla.novell.com/show_bug.cgi?id=664828

https://bugzilla.novell.com/show_bug.cgi?id=664828#c0


           Summary: Data binding pull should only happens if control
                    XXXChanged event has fired
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: x86
        OS/Version: Windows 7
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: cvolzke at live.com.au
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)
AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1036 Safari/532.5

A data binding pull from the control to the data source should only occur if
the control property XXXChanged event has fired, if that event is defined.


Reproducible: Always

Steps to Reproduce:
Unit test to reproduce:

[Test]
public void Test_DataBindingPushOnlyIfControlPropertyChanged()
{
    TestDataSource dataSource = new TestDataSource();
    Control.DataBindings.Add("ControlValue", dataSource, "IntProperty");
    Form.Controls.Add(Control);
    Control otherControl = new Control();
    Form.Controls.Add(otherControl);
    Form.Show();
    Application.DoEvents();
    dataSource.IntPropertySet = false;

    otherControl.Focus();
    Control.Focus();
    Control.ControlValue = 2;
    otherControl.Focus();
    AssertEquals(2, dataSource.IntProperty, "Property set from control to data
source");
    AssertEquals(true, dataSource.IntPropertySet, "Property set from control to
data source");
    dataSource.IntPropertySet = false;

    otherControl.Focus();
    Control.Focus();
    otherControl.Focus();
    AssertEquals(2, dataSource.IntProperty, "Property set from control to data
source");
    AssertEquals(false, dataSource.IntPropertySet, "Property set from control
to data source");
    dataSource.IntPropertySet = false;
}

Form form;
Form Form
{
    get { return form ?? (form = new Form()); }
}

TestControl control;
TestControl Control
{
    get { return control ?? (control = new TestControl()); }
}

class TestControl : Control
{
    public event EventHandler ControlValueChanged;
    public int ControlValue
    {
        get
        {
            int result;
            int.TryParse(Text, out result);
            return result;
        }
        set
        {
            Text = value.ToString();
            if (ControlValueChanged != null)
            {
                ControlValueChanged(this, EventArgs.Empty);
            }
        }
    }
}

class TestDataSource
{
    public event EventHandler IntPropertyChanged;

    public const int IntPropertyDefaultValue = 5;
    int intProperty = IntPropertyDefaultValue;
    public int IntProperty
    {
        get { return intProperty; }
        set
        {
            intProperty = value;
            if (IntPropertyChanged != null)
            {
                IntPropertyChanged(this, EventArgs.Empty);
            }
            IntPropertySet = true;
        }
    }

    public bool IntPropertySet { get; set; }
}

Actual Results:  
The unit test fails.

Expected Results:  
The unit test should pass, as it does with ms.net.


The changes below fixes and issue and cause the unit test above to pass.

Code added to Binding:
    private bool modified;

Code added to Binding.PullData:
    bool PullData (bool force)
    {
        if (control_property != null && control_property.SupportsChangeEvents
&& !modified) // line added
            return true; // line added
        if (IsBinding == false || manager.Current == null)
            return true;

#if NET_2_0
        if (!force && datasource_update_mode == DataSourceUpdateMode.Never)
            return true;
#endif

        data = control_property.GetValue (control);
#if NET_2_0
        if (data == null)
            data = datasource_null_value;
#endif

        try {
            SetPropertyValue (data);
            modified = false; // line added
        } catch (Exception e) {
    }

Code added to Binding.PushData:

    try {
        data = FormatData (data);
        SetControlValue (data);
        modified = false; // line added

Code added to Binding.ControlPropertyChangedHandler:

    void ControlPropertyChangedHandler (object o, EventArgs args)
    {
        modified = true; // line added
        if (datasource_update_mode != DataSourceUpdateMode.OnPropertyChanged)
            return;

-- 
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