Click here to Skip to main content
15,881,864 members
Please Sign up or sign in to vote.
3.12/5 (3 votes)
See more:
When checkbox is checked as true, it is calling the checkedChanged event handler.
C#
this.signedChkBx.Checked = true;


If it is checked as false it is not calling the checkedChanged event handler.
C#
this.signedChkBx.Checked = false;


My CheckedChanged event handler is

C#
private void signedChkBx_CheckedChanged(object sender, EventArgs e)
        {
            if (this.signedChkBx.Checked == false)
            {
                ChangedSettings.changedReason = 0;
            } // if
            else
            {
                ChangedSettings.changedSignedBy = 1;
            } // else
        }


What can the reason be for not calling in case of false?
Posted
Comments
dan!sh 6-Oct-15 0:43am    
It will depend on order of these lines of code. If on form load, you are setting checked as false, that is not a check change since by default the check box is unchecked. Can you update your question with some more code? Where are you setting this as false and how are you binding event handler?
Krunal Rohit 6-Oct-15 0:43am    
Hmm, Strange. Code looks good.
Can you try using debugger ? Or you might want to change the order of your change event.

-KR
[no name] 6-Oct-15 0:45am    
Is there any javascript code is injected for the checkbox. Please recheck.

1 solution

If CheckedChanged handler isnt working, you can try these 3 things:

1). Create your own bool method like, isChecked(checkBox1):

Code:
C#
public bool isChecked(CheckBox checkbox){
  if (checkbox.CheckState == CheckState.Checked) return true;
  else return false;
}


Example:
C#
if (isChecked(checkBox1)) {
  MessageBox.Show("Checked");
} else {
  MessageBox.Show("Not Checked");
}


2). Try using CheckStateChanged Handler.
3). Clean build the project.

I recommend the first one :) .
 
Share this answer
 
Comments
Southmountain 5-Sep-22 14:47pm    
thanks for your tricks! I used 1) and it works.

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