Cannot data bind to a control when Control.Visible == false

后端 未结 7 664
独厮守ぢ
独厮守ぢ 2020-12-14 11:22

In WinForms with C# 4.0 / C# 2.0, I cannot bind to a control if the control\'s visible field is false:

this.checkBox_WorkDone.DataBindings.Add(\"Visible\", W         


        
7条回答
  •  执笔经年
    2020-12-14 12:16

    My workaround:

    private void Form_Load(object sender, EventArgs e)
    {
        button.Visible = true;
        button.DataBindings["Visible"].ReadValue();
    }
    

    button.Visible = true; is needed to force creating control (in other word, associate Button class instance with actual Win32 window handle).

    Because data binding won't work until control is created. So create control at first.

    And then reload actual Visible value from data source by calling Binding.ReadValue().

提交回复
热议问题