I have barely any experience with WinForms, but开发者_如何学JAVA I'm fairly sure that this is a simple task. I just need to enable and disable the Enabled property of a textbox based on the SelectedIndex of a ComboBox.
Can this be done in the designer using DataBindings, or am I required to write a handler of some kind?
You can bind it, but you have to write a Value -> Boolean converter to do the logic. I would suggest since winforms doesn't support the ViewModel paradigm you just go with an event handler as you'd likely have to define your databind in code anyway.
public void MyComboBox_SelectedIndexChanged(object sender, EventArgs args)
{
ComboBox box = sender as ComboBox;
if (box != null) return;
switch(box.Text)
{
case "Value1":
case "Value2":
case "Value3":
myTextBox.Enabled = false;
break;
default:
myTextBox.Enabled = true;
}
}
精彩评论