I have a notional Boolean value stored in the Registry. Actually it's
a REG_DWORD capable of taking values of either 0 or 1.
So, I need to populate a checkbox on a form dependent on this value.
1. I tried this:
chkLogToFile.Checked =
Boolean.Parse(LogFileKey.GetValue("LogToFile"));
No luck - "The best overloaded method match for 'bool.Parse(string)'
has some invalid arguments"
2. I tried this:
chkLogToFile.Checked =
Boolean.Parse(LogFileKey.GetValue("LogToFile").ToS tring());
No luck - "String was not recognized as a valid Boolean"
3. I tried this:
chkLogToFile.Checked = (bool)LogFileKey.GetValue("LogToFile");
No luck - "Specified cast is not valid"
NOTE: If I run this in the Debug ("Immediate") pane I get "Cannot
unbox 'LogFileKey.GetValue("LogToFile")' as a 'bool'"
4. I tried this:
chkLogToFile.Checked =
(bool)LogFileKey.GetValue("LogToFile").ToString();
No luck - "Cannot convert type 'string' to 'bool'"
5. I tried this:
chkLogToFile.Checked =
Convert.ToBoolean(LogFileKey.GetValue("LogToFile") );
Hooray!
I realise that this is likely my woeful ignorance, but this is the
first time that I've come across a language that wilfully refuses to
equate numeric 0 with boolean false.
Edward