PC Review


Reply
Thread Tools Rate Thread

Checkbox displays 'check' instead of the assigned caption

 
 
Jeremy
Guest
Posts: n/a
 
      30th Apr 2009
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?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reference frame caption associated with a checkbox novice973 Microsoft Excel Programming 2 8th Apr 2008 11:53 PM
how to execute a macro assigned to a checkbox in vba pieterklinker@gmail.com Microsoft Excel Programming 4 21st Jun 2006 09:31 AM
CheckBox as Groupbox caption =?Utf-8?B?am9zZWY=?= Microsoft Dot NET Framework Forms 2 5th Aug 2005 02:48 PM
Form displays hourglass rather than updating the caption of a labe =?Utf-8?B?SmVmcmV5?= Microsoft Access VBA Modules 1 19th May 2005 06:40 PM
Change Caption in checkbox =?Utf-8?B?SGFucw==?= Microsoft Excel Programming 3 21st Mar 2004 05:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:07 PM.