[Mono-bugs] [Bug 664831] New: Inconsistent Binding.ReadValue behaviour when binding hasn't begun

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Jan 16 17:14:58 EST 2011



           Summary: Inconsistent Binding.ReadValue behaviour when binding
                    hasn't begun
    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/ Safari/532.5

When calling Binding.ReadValue() when binding hasn't begun, ms.net sets a null
(or default) value on the control whereas mono sets a value from the data

Reproducible: Always

Steps to Reproduce:
Unit test to reproduce:

public void Test_ReadValueWhenNotBinding()
    TestDataSource dataSource = new TestDataSource();
    dataSource.IntProperty = 10;
    Control.ControlValue = 10;
    var binding = Control.DataBindings.Add("ControlValue", dataSource,

    AssertEquals(10, Control.ControlValue, "Pre-condition");
    AssertEquals(0, Control.ControlValue, "Null or default value should be set
on the data source");

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

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

Actual Results:  
Unit test fails

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

These changes fix the issue and cause the test above to pass.

Code added to Binding.PushData:
    try {
        data = FormatData (data);
        if (!IsBinding) // line added
            data = null; // line added
        SetControlValue (data);
    } catch (Exception e) {

Code added to Binding.PushData:
    void PushData (bool force)
        if (manager != null && (manager.Count == 0 || manager.Position == -1))
// line added
            SetControlValue(null); // line added
        if (manager == null || manager.IsSuspended || manager.Count == 0 ||
manager.Position == -1)

Code added to Binding.SetPropertyValue
    private void SetPropertyValue (object data)
        PropertyDescriptor pd = TypeDescriptor.GetProperties
(manager.Current).Find (binding_member_info.BindingField, true);
        if (pd.IsReadOnly)
        data = ParseData (data, pd.PropertyType);
            pd.PropertyType != typeof(object) && data is DBNull ? null : //
this line of the statement added

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