Click here to Skip to main content
15,886,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private void cmbWinLoss_SelectedIndexChanged(object sender, EventArgs e)
{
  if (cmbWinLoss.selectedvalue == "-")
  {
      cmbLossTo.Enabled = false;
      cmbLossReason.Enabled = false;
      txtDetailsLosRsn.Enabled = false;
  }
  else
  {
      cmbLossTo.Enabled = true;
      cmbLossReason.Enabled = true;
      txtDetailsLosRsn.Enabled = true;
  }
}

but it is not working give me solution
Posted
Updated 4-Nov-14 1:25am
v2
Comments
Rob Branaghan 4-Nov-14 7:03am    
Are you populating your combobox dynamically?
If you have then I think you want to look at SelectedItem, rather than value?
ZurdoDev 4-Nov-14 10:23am    
All you have to do is debug it and you'll see the problem.

1 solution

C#
private void cmbWinLoss_SelectedIndexChanged(object sender, EventArgs e)
{
    cmbLossTo.Enabled =
        cmbLossReason.Enabled =
            txtDetailsLosRsn.Enabled =
                (! (cmbWinLoss.SelectedItem.ToString() == "-"));
}
 
Share this answer
 
v2
Comments
Alan N 4-Nov-14 7:41am    
I bet that gives a compiler warning about "possible unintended reference comparison" and I'm sure you meant to cast SelectedItem to string. Literal string pooling by the compiler or string interning by the CLR will usually ensure that the references are equal but it isn't something that should be relied upon.
BillWoodruff 4-Nov-14 8:28am    
I agree with you, Alan, it's better practice to not rely on object => string implicit conversion. Interesting that ReSharper doesn't flag this one. Code changed, thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900