Adding Radio Buttons (Visual Basic .NET Tutorial) [Office 2003 SDK Documentation]
Previous Adding Help Content
The following steps show you how to add a collection of radio buttons to the SimpleSample smart document.
The first thing you will need to do is add a constant for the radiobutton element in the SimpleSample schema. Insert the following code into the general declarations section of your code module below the existing constants.
Const cRADIO As String = cNAMESPACE & "#radiobutton"
Next you need to add 1 to the cTYPES constant. Remove the existing cTYPES constant and enter the following code or change your code to match.
Const cTYPES As Integer = 5
Now you are ready to modify the existing code. The subroutines you will need to modify are SmartDocXMLTypeName, SmartDocXMLTypeCaption, ControlCount, ControlID, ControlTypeFromID, and ControlCaptionFromID.
In the SmartDocXMLTypeName property subroutine, insert the following code.
Case 5 SmartDocXmlTypeName = cRADIO
In the SmartDocXMLTypeCaption property subroutine, insert the following code.
Case 5 SmartDocXmlTypeCaption = "Radio buttons"
In the ControlCount property subroutine, insert the following code.
Case cRADIO ControlCount = 1
In the ControlID property subroutine, insert the following code.
Case cRADIO ControlID = ControlIndex + 400
In the ControlTypeFromID property subroutine, insert the following code.
Case 401 ControlTypeFromID = C_TYPE.C_TYPE_RADIOGROUP
In the ControlCaptionFromID property subroutine, insert the following code.
Case 401 ControlCaptionFromID = "Pick your favorite color"
Next, you need to specify the value of the items in the radio buttons. To do this you use the PopulateRadioGroup method. Use the List parameter to specify each item in the radio group and use the Count parameter to specify the number of items in the List parameter. Insert the following code into the PopulateRadioGroup method subroutine.
Select Case ControlID Case 401 Count = 5 List(1) = "Red" List(2) = "Blue" List(3) = "Yellow" List(4) = "Purple" List(5) = "Green" InitialSelected = -1 End Select
Note The InitialSelected parameter specifies the number of the item to select when the radio group is initially displayed. Use -1 to indicate that none of the items in the list are initially selected.
Then, in the OnRadioGroupSelectChange method, write the code that you want run when a user selects an item from the list of radio buttons. The Target parameter can be used to access the element to which the control applies. In the following code, you create a Word Range object from the XML element and replace the existing text in the Word document with the new text specified in the String.
Dim objRange As Microsoft.Office.Interop.Word.Range Select Case ControlID Case 401 objRange = Target.XMLNodes(1).Range objRange.Text = "My favorite color is " & Value & "." End Select
Recompile your SimpleSample smart document DLL and copy it to the deployment location that you specified earlier. When you reopen your SimpleSample smart document, delete the SimpleSample XML expansion pack, and then re-add it to the document.
Next Adding Checkboxes