2

I'm targeting the framework 4.0 and this works fine on the development machine, I can see at startup the form with the textbox displaying binded message in it. But when I deploy the executable on any other machine it won't work claiming that "cannot bind to the property or column Note on the DataSource". The very strange thing is that it works well on any machine if I compile targeting the 3.5 framework. Someone could explain this odd behaviour? What can be different between development environment and client machines?

namespace Demo
{
    public partial class Form1 : Form
    {
        private readonly SimpleDataContext _dataContext;

        public Form1()
        {
            InitializeComponent();

            _dataContext = new SimpleDataContext { Prop = new SimpleProp { Note = "hi!" }};
            textBox1.DataBindings.Add("Text", _dataContext, "Prop.Note");         
        }
    }

    public class SimpleDataContext
    {
        public SimpleProp Prop { get; set; }
    }

    public class SimpleProp
    {
        public string Note { get; set; }
    }  
}

1 Answers1

2

Breaking change in 4.0. See .Net 4.0 simple binding issue

The work around is to use a BindingSource:

public Form1() {
  InitializeComponent();
  _dataContext = new SimpleDataContext { Prop = new SimpleProp { Note = "hi!" } };
  BindingSource bs = new BindingSource(_dataContext, null);
  textBox1.DataBindings.Add("Text", bs, "Prop.Note");    
}
LarsTech
  • 80,625
  • 14
  • 153
  • 225