Checkbox displays 'check' instead of the assigned caption

J

Jeremy

Hi,
I added a checkbox using the following code in C#
private void AddCheckbox(RectangleF location, string caption)
{
OLEObjects all = (OLEObjects) activeWorksheet.OLEObjects(Type.Missing);
OLEObject obj = all.Add("Forms.CheckBox.1", Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, location.X,
location.Y, location.Width, location.Height);
Object[] text = new object[] { caption };

obj.Object.GetType().InvokeMember("Caption", BindingFlags.SetProperty,
null, obj.Object, text);
text[0] = true;
obj.Object.GetType().InvokeMember("FontBold", BindingFlags.SetProperty,
null, obj.Object, text);
obj.Object.GetType().InvokeMember("Value", BindingFlags.SetProperty,
null, obj.Object, text);
Marshal.ReleaseComObject(all);
Marshal.ReleaseComObject(obj);
}

And it works, but when the sheet is displayed, the caption of the checkbox
is 'check', and the checkbox appears unselected. If I click on the checkbox,
then the correct caption appears, and the checkbox briefly displays as
checked before becoming unchecked.
How do I get it to display correctly without the user clicking on it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top