I have three checkboxes in my form. The problem is that when I check all three, I only received one checkbox. how can I fix this?
my code:
private void button1_Click(object sender, EventArgs e)
{
ConfigOptions itemToSave = 0;
if (autoCapsNames.Checked)
{
itemToSave |= ConfigOptions.AutoCapsStr;
}
if (autoSort.Checked)
{
itemToSave |= ConfigOptions.IntantOrganization;
}
if (showLinesNumbers.Checked)
{
itemToSave |= ConfigOptions.ShowLinesNumber;
}
SaveConfigs(itemToSave);
}
Thanks
The previous answer should solve your issue, but it changes the way you handle the data.
If you want to use bitwise OR method (as you are doing now), make sure you have correctly defined
ConfigOptions. Values assigned toConfigOptions.AutoCapsStr,ConfigOptions.IntantOrganizationandConfigOptions.ShowLinesNumbershould be chosen in such a way to define the values you set in a unique way.If
ConfigOptionsis anenum, you can try to define it like this:Then, you can use it inside your
SaveConfigsmethod (or in your loading method, if you just save the numeric value) to test values set like this: