Adding List Boxes and Combo Boxes (Visual Basic .NET Tutorial) [Office 2003 SDK Documentation]
Previous Adding Check Boxes
The following steps show you how to add a list box to the SimpleSample smart document. This is the same basic process that you would use to add a combo box.
The first thing you need to do is add a constant for the listbox element in the SimpleSample schema. Insert the following code into the general declarations section of your code module, below the existing constants.
Const cLIST As String = cNAMESPACE & "#listbox"
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 = 7
Now you are ready to modify the existing code to insert the list box. The subroutines you need to modify are SmartDocXMLTypeName, SmartDocXMLTypeCaption, ControlCount, ControlID, ControlTypeFromID, and ControlCaptionFromID.
In the SmartDocXMLTypeName property subroutine, insert the following code.
Case 7 SmartDocXmlTypeName = cLIST
In the SmartDocXMLTypeCaption property subroutine, insert the following code.
Case 7 SmartDocXmlTypeCaption = "List box"
In the ControlCount property subroutine, insert the following code.
Case cLIST ControlCount = 1
In the ControlID property subroutine, insert the following code.
Case cLIST ControlID = ControlIndex + 600
In the ControlTypeFromID property subroutine, insert the following code.
Case 601 ControlTypeFromID = C_TYPE.C_TYPE_LISTBOX
In the ControlCaptionFromID property subroutine, insert the following code.
Case 601 ControlCaptionFromID = _ "Select your favorite baseball team."
The PopulateListOrComboContent method specifies the value of the items in the list. This list is created similarly to radio buttons. The following code specifies the Count parameter; then the List parameter specifies the value of each of the five items in the list.
Select Case ControlID Case 601 Count = 5 List(1) = "Mariners" List(2) = "Mets" List(3) = "Dodgers" List(4) = "Red Sox" List(5) = "Orioles" InitialSelected = -1 End Select
Note The InitialSelected parameter specifies the number of the item to select when the radio group is initially displayed. The number of the item is the array index number as it is specified in the List parameter. Use -1 to indicate that none of the items in the list are initially selected.
In the OnListOrComboSelectChange method, you would specify what happens when a user selects an item from the list. The following code specifies that new text that contains the value of the selected item replaces the current text in the active element.
Dim objRange As Microsoft.Office.Interop.Word.Range Select Case ControlID Case 601 objRange = Target.XMLNodes(1).Range objRange.Text = "My favorite baseball team 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 Images