Search code examples
c#.netwinformsdata-bindingbindingsource

Binding Control Properties to BindingSource


How can I bind the Property (Location.X) of a C# button to a BindingSource?

I have tried the following code

myButton.DataBindings.Add("Location.X", myButtonsBindingSource, "Button_X");

but it is not working, it works for example if I want to bind the Text property of the button but not for X & Y coordinators.

any ideas or other ways to bind Location.X property of my button to a binding source programmatically?

Thanks


Solution

  • You can use Left property of the button instead:

    myButton.DataBindings.Add("Left", myButtonsBindingSource, "Button_X");
    

    Above statement creates a data-binding between Button_X property of the object which you have in DataSource of myButtonsBindingSource and Left property of myButton.