Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
I was trying to implement a small piece of code for my checkbox within a method using wpf, and i got this error.

"
VB
Error   1   The event;System.Windows.Controls.Primitives.ToggleButton.Checked& can only appear on the left hand side of += or -= "




C#
public void test()
{

if (checkBox1.Checked)
                   {
                      MessageBox.Show("checkbox is checked now");
                     }
else
{
MessageBox.Show("checkbox is unchecked now");
}
}


Any help would be much appreciated. Thanks
Posted
Updated 13-Sep-11 8:16am
v2

1 solution

checkBox1.Checked is the event which is generated when the state of the checkbox is changed. checkBox1.IsChecked is the state of the checkbox.
So to determine the current state of the checkbox use
if (checkBox1.IsChecked)
 
Share this answer
 
Comments
steersteer 13-Sep-11 14:26pm    
Thanks
steersteer 13-Sep-11 14:44pm    
thanks. Could you please tell me how to uncheck the checkbox once after the messagebox is displayed ? ( i tried checkbox1.ischecked == false but that didn't work. I want the checkbox to be unchecked if it is checked and checked if it is not checked.
BillW33 13-Sep-11 15:03pm    
That should be checkbox1.IsChecked = false; note that there only 1 equals sign.

If this solution answers your question you should mark it as the 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