WinForms (C#) Databinding Object to Checkbox.Checked Property

Posted by Trevor Sullivan on Stack Overflow See other posts from Stack Overflow or by Trevor Sullivan
Published on 2010-05-16T16:31:57Z Indexed on 2010/05/16 16:40 UTC
Read the original article Hit count: 1085

Filed under:
|
|
|
|

Hello,

I'm writing a WinForms app, and am trying to bind a boolean property on a .NET object to a Checkbox's "checked" property. I am successfully creating the binding, but when I change the source property's value from false to true (I have a button that toggles it), the checkbox's "checked" property does not reflect that change.

if (chkPreRun.DataBindings["Checked"] == null)
{
    Debug.WriteLine("Adding chkPreRun databinding");
    Binding _binding = chkPreRun.DataBindings.Add("Checked", NwmConfig, "PreRun")

    // Added this just to ensure that these were being set properly
    _binding.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
    _binding.ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;
}

I am able to successfully bind the text property to the value of a TextBox, for example. I'm not sure what I'm missing while binding to the "Checked" property, however.

Cheers,

Trevor

© Stack Overflow or respective owner

Related posts about winforms

Related posts about c#