Question

I would like to save the user radio- button preference in the Settings file.

Therefore, I have created a setting property called radioButtonIsChecked boolean typed.

radioButton.Checked = Properties.Settings.Default[radioButton.Name + "IsChecked"];

When I try the code above I get an error that object cannot be converted to bool.
I understand the reason is that the returned value from Settings.Default indexer is object.

Is there a way to refer the settings- property type when retrieved from by-name-indexer?

Was it helpful?

Solution

Assuming the retrieved value will be of the right type, just cast it:

radioButton.Checked = (bool) Properties.Settings.Default[radioButton.Name + "IsChecked"];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top