I'm assuming that you're talking about WinForms
You can not do it that way. The following line assigns null to myCheckBox, as objCheckBox is of type string and not of type CheckBox.
CheckBox myCheckBox = objCheckBox as CheckBox;
What you need to do is iterate all controls on the form to find the control named checkBoxName. You can do it via LINQ, or you can do it like this:
Control[] controls = this.Find(checkBoxName, true);
if (controls != null && controls.Length > 0)
{
(controls[0] as CheckBox).Checked = words[1] != "-1";
}
A LINQ approach could look like this:
Control c = (from Control c in this.Controls where c.Name.Equals(checkBoxName) select c).FirstOrDefault();
if (c != null)
{
....
}
Please note that if the CheckBox is not a direct child of the form itself, the LINQ approach won't find it. To make sure it is always found, you'll need to recursively also search container controls - for example: If you find a control which is a Panel, you need to also search the panel's children.
I edited my code according to the comments - just remembered the Find method, too.
stringinobjCheckBoxand trying to convert that asCheckBox. That obviously won't work.