Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
when checking check boxes some times it working and some time not appropriately?
I found that even i checked the checkbox still it's property is false . How can i fix this?

What I have tried:

C#
private void checkPOD_CheckedChanged(object sender, EventArgs e)
       {
           if (checkMobAd.Checked)
           {
               txtPOD1.ReadOnly = false;
           }
           else
           {
               txtPOD1.Clear();
               txtPOD1.ReadOnly = true;
           }
       }
Posted
Updated 17-Nov-16 3:56am
v2

It looks to me like you're checking the wrong control. The event is attached to checkPOD, but the checkbox you're looking at is checkMoAd.
 
Share this answer
 
I'd suspect that it's working every time: it certainly does for me, and I'd be surprised if a bug like that had gone unnoticed for so many years.
I suspect that it just isn't doing what you expect because it's not monitoring the same checkbox as causes the event to fire. Try changing it to use the actual CheckBox and see what happens:
C#
private void checkPOD_CheckedChanged(object sender, EventArgs e)
    {
    CheckBox cb = sender as CheckBox;
    if (cb != null)
        {
        if (cb.Checked)
            {
            txtPOD1.ReadOnly = false;
            }
        else
            {
            txtPOD1.Clear();
            txtPOD1.ReadOnly = true;
            }
        }
    }
 
Share this answer
 

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