Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Designing Smart Documents in Office 2003 : Page 9

Today, most organizations have a wealth of Office documents that contain critical information, but finding, extracting, and reusing that information programmatically remains a largely unrealized goal. Fortunately, that's changing as XML processing in Microsoft Office 2003 grows up.


advertisement
Populating ComboBoxes in the Itemname and Region Nodes
You've seen how to use the ActiveX control for the documentRoot XMLType; the other nodes use a ComboBox control. Here's the PopulateListOrComboContent method used in the region XMLType.

Public Overrides Sub PopulateListOrComboContent( _ ByVal ControlID As Integer, _ ByVal ApplicationName As String, _ ByVal LocaleID As Integer, _ ByVal Text As String, _ ByVal Xml As String, _ ByVal Target As Object, _ ByVal Props As Microsoft.Office.Interop.SmartTag. _ ISmartDocProperties, ByRef List() As String, _ ByRef Count As Integer, _ ByRef InitialSelected As Integer) regionNode = DocumentUtils.GetData( _ DocumentUtils.DataTableType.region) regions = New Hashtable regionList = New ArrayList ControlID = DocumentUtils.GetRealControlID( _ ControlID) Select Case ControlID Case 1 Dim regionNodes As XmlNodeList = _ regionNode.SelectNodes("//region") Dim regionEnum As IEnumerator = _ regionNodes.GetEnumerator Dim intCount As Integer = regionNodes.Count ReDim Preserve List(intCount - 1) Dim iterator As Integer = 0 While regionEnum.MoveNext Dim node As XmlNode = _ CType(regionEnum.Current, XmlNode) regions.Add(node.Attributes("ID").Value, node.Attributes("Description").Value) regionList.Add(node.Attributes("ID").Value) List.SetValue(CType(node.Attributes( _ "Description").Value, String), iterator) iterator = iterator + 1 End While Count = intCount - 1 InitialSelected = 1 intSelectedValue = InitialSelected End Select End Sub

In the preceding method note these critical items.

  • List()—This is a ByRef array parameter that the API uses to populate the combo or list display values. You can use the List.SetValue method to set the value at the proper index as shown above.
  • CountByRef parameter where you can set the number of items being returned.
  • InitialSelected—Set this ByRef parameter to the index value of the item you want to be the default selection in the combo box. The sample code uses 1.
The code uses an ArrayList (regionList) to maintain the ID values because of a constraint in the way this COM-based combo box works. COM-based combo boxes don't have the concepts of DisplayMember and ValueMember; therefore you have to maintain an ArrayList of primary keys and match them with the appropriate selected value. When a user selects an item, the following OnListOrComboSelectChange method shown below passes a Selected parameter that provides the selected item's index, while the Value parameter provides the corresponding display value.

Public Overrides Sub OnListOrComboSelectChange( _ ByVal ControlID As Integer, _ ByVal Target As Object, _ ByVal Selected As Integer, _ ByVal Value As String) intSelectedValue = Selected End Sub

The region XMLType has an Invoke method called when a user clicks the Apply button. Note the way it fetches the context of the "region" node and later adds its attribute items "id," and "tax."



Dim rangeNode As Word.XMLNode = CType(Target, _ Word.Range).XMLNodes(1) Dim idAttr As Word.XMLNode = _ rangeNode.Attributes.Add("id", _ Constants.DOCUMENT_NAMESPACE) idAttr.NodeValue = CType(regionList.Item( _ intSelectedValue - 1), String) Dim taxAttr As Word.XMLNode = _ rangeNode.Attributes.Add("tax", _ Constants.DOCUMENT_NAMESPACE) taxAttr.NodeValue = regionNode.SelectSingleNode( _ "//region[@ID='" + regionList.Item( _ intSelectedValue - 1) + "']/@Tax").InnerText rangeNode.Text = regions.Item( _ regionList.Item(intSelectedValue - 1))

After adding these attributes your document becomes valid against the schema. You set the attributes and value for the itemname node and populate the total price and other nodes in a similar way. I suggest you take a step-by-step debug mode walkthrough approach until you're sure everything works.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date