I need to convert int and or bool to checkState
int ValueCheck;
private void gsCheck1_CheckedChanged(object sender, EventArgs e)
{
CheckBox box = sender as CheckBox;
box.CheckState = ValueCheck; // doesn't work
this.gsCheck2.CheckState = ValueCheck; // should be 1 or 0 ?
}
As you can see I want to change (this.gsCheck2) CheckState by changeing (this.gsCheck1) CheckState and end up with a integer value which is need.
Update….
problem solved
private int ValueCheck(CheckState Check)
{
if (Check == CheckState.Checked)
return 1;
else
return 0;
}
private void gs_CheckedChanged(object sender, EventArgs e)
{
CheckBox box = sender as CheckBox;
MessageBox.Show(box.Name + "="+ ValueCheck(box.CheckState).ToString());
}
CheckBox.Checkedwhich is the boolean property.box.CheckState = (CheckState)ValueCheck;?:operator.Update according to comments:
Either declare the ValueCheck as a CheckState:
Or convert the int value to a CheckState value:
The cast back the CheckState value to int:
Update
FYI, instead of writing the ValueCheck method, there is a C# operator
?:operator I mentioned above, which you can do:Which is a translation of: