View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Fabz[_3_] Fabz[_3_] is offline
external usenet poster
 
Posts: 11
Default Grouping radio buttons?

Sorry, forgot to mention that I am writing C# code for my ComAddIn. Although
there indeed is an OptionButton interface in my
Microsoft.Office.Interop.Excel namespace, it does not seem to be the proper
way to implement radio buttons (this might be different using VBA code).
What is confusing to me is that there is no GroupBox item inside my VSTO
toolbox to be chosen and drag'n'dropped on my worksheet. I only can do this
programmatically. Don't know why.

However, finally I got a working example:

// 1. Make new GroupBox instance
GroupBox myGroupBox = new GroupBox();

// 2. Add radio buttons
myGroupBox.Controls.Add(radioButton1);
myGroupBox.Controls.Add(radioButton2); // etc.

// 3. Position radio buttons in relation to the GroupBox
myGroupBox.Controls[1].Left = targetDataRadioButtons.Controls[0].Right + 10;

// Position the group box inside cells [row: 3, col: 2] and [row: 3, col: 8]
Excel.Range left = (Excel.Range)Cells[3, 2];
Excel.Range right = (Excel.Range)Cells[3, 8];

// 4. IMPORTANT: Add the GroupBox to this sheet's collection of Controls!
Controls.AddControl(myGroupBox, Range[left, right], "foo");


What is weird also is the 3rd point. To position the radio buttons, I have
to do as stated. When trying to position the radio buttons themselves, this
does not work:
// Works:
myGroupBox.Controls[1].Left = targetDataRadioButtons.Controls[0].Right + 20;

// Does not work:
radioButton2.Left = radioButton1.Right + 20;

Don't know whether there is a good solution to this problem.

Greetz
Fabz


"John Keith" wrote in message
...
see this site for a short tutorial.

http://www.functionx.com/excel/artic...diobuttons.htm


Thank you for posting this url (although the images did not load for
me :-( )

I have been looking for a tutorial on radio buttons and hadn't found
anything good yet and I want to learn more about them now that I have
a situation where I can use them. If anyone has any other good sites
on radio buttons please post.


John Keith