Is there anyway to disable a combobox if a different combobox has some sort of text or value in it. I have tried a couple things and can\'t seem to get it to work.
B
You can take a look here
http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/04f92630-8c66-4e9d-8c95-22716d86177f
Something similar to this, only set whatever property you want, or don't clear it, or whatever. (test combos were not data bound)
public partial class Form1 : Form
{
bool fireEvents = true;
public Form1()
{
InitializeComponent();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (fireEvents) doCheck(sender, e);
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (fireEvents) doCheck(sender, e);
}
private void doCheck(object sender, EventArgs e)
{
fireEvents = false; // because we don't have a way to cancel event bubbling
if (sender == comboBox1)
{
comboBox2.SelectedIndex = -1;
}
else if (sender == comboBox2)
{
comboBox1.SelectedIndex = -1;
}
fireEvents = true;
}
}
You can handle the SelectedValueChanged event of both the combo boxes and if any of the combo has your required value disable the other one
Use the SelectedValueChanged event of combobox1 to check for the selected values. Disable or enable combobox2 based upon that.
private void combobox1_SelectedValueChanged(object sender, Eventargs e)
{
if (combobox1.SelectedValue == myDisableValue)
combobox2.Enabled = false;
else
combobox2.Enabled = true;
}