I have a static utilities class that contains the following methods
public static void BindEnabled(Control control, object dataSource, string dataMember)
{
control.DataBindings.Add("Enabled", dataSource, dataMember, false, DataSourceUpdateMode.OnPropertyChanged);
}
public static void BindCheck(CheckBox check, object dataSource, string dataMember)
{
check.DataBindings.Add("Checked", dataSource, dataMember, false, DataSourceUpdateMode.OnPropertyChanged);
}
public static void BindVisible(Control control, object dataSource, string dataMember)
{
control.DataBindings.Add("Visible", dataSource, dataMember, false, DataSourceUpdateMode.OnPropertyChanged);
}
public static void BindText(TextBox box, object dataSource, string dataMember)
{
box.DataBindings.Add("Text", dataSource, dataMember, true, DataSourceUpdateMode.OnPropertyChanged);
My object code is
public class Holder
{
public bool MaterialChk { get; set; }
public string MaterialName { get; set; }
}
I set up my binding as follows;
var _holder = new Holder();
BindingSource bs = new BindingSource { DataSource = _holder };
Utility.BindCheck(chkMaterial, bs, "MaterialChk");
Utility.BindText(txtMaterial, bs, "MaterialName")
Utility.BindVisible(txtMaterial, bs, "MaterialChk")
If I place these controls on the first tab of my multi tab control then the binding works as expected.
If I place these controls on the fourth tab then Material Name does not become visible when the check box is checked.
However if I use BindEnabled instead of BindVisible this works on both tabs.
Aucun commentaire:
Enregistrer un commentaire