Adding Functionality to the Actions Pane Controls

The code in Listing 5.14 shows how to add and remove actions pane controls on the actions pane based on the ContextEnter and ContextLeave events of XMLNodes within the document. Next, you'll learn how to make the controls functional.

You can add code to prepopulate the combo boxes. Typically, you would bind these controls to a data source. However, for the purposes of this example, you will hard-code a few names to populate the Author combo box in the Load event of the actions pane control.

1. Add the code in Listing 5.15 to the Load event handler of

ActionsPaneControl1, and the Click event handler of Button1 on ActionsPaneControl1.

When the Insert button is clicked, the code adds the data from the actions pane control to the document by assigning the value of the Text property of the controls to the Text property of the corresponding XMLNode control. The text in each text box is then removed.

Listing 5.15. Adding data to actions pane controls

Private Sub ActionsPaneControl1_Load(ByVal sender As _

System.Object, ByVal e As System.EventArgs) Handles _ MyBase.Load

With Me.ComboBox1.Items

.Add("Kathleen McGrath") .Add("Paul Stubbs") End With

Me.ComboBox1.SelectedIndex = 0 End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click

' Add the contents of the controls to the document. With Globals.ThisDocument

.AddressAuthorNode.Text = Me.ComboBox1.Text .AddressAddresseeNode.Text = Me.TextBox1.Text .AddressReNode.Text = Me.TextBox2.Text End With

'Clear data out of the text boxes. Me.TextBox1.Text = "" Me.TextBox2.Text = ""

End Sub

2. Add the code in Listing 5.16 to the Load event handler of ActionsPaneControl2.

This code populates the Salutation combo box with titles, and populates the Closing combo box with standard closings when the actions pane is loaded.

Listing 5.16. Populating controls on the actions pane with text

Private Sub ActionsPaneControl2_Load(ByVal sender As _

System.Object, ByVal e As System.EventArgs) Handles _ MyBase.Load

With Me.ComboBox1.Items .Add("Miss ") .Add("Mr. ") .Add("Mrs. ") .Add("Ms. ") End With

With Me.ComboBox2.Items

.Add("Very truly yours,") .Add("Yours truly,") .Add("Sincerely,") End With

3. Add the code in Listing 5.17 to the Click event handler of Button1 on ActionsPaneControl2.

When the Insert button is clicked, the code writes the values of the controls into the document and clears the control content.

Listing 5.17. Writing values in the actions pane to the document

Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click

With Globals.ThisDocument

.ContentSalutationNode.Text = Me.ComboBox1.Text & " " _

& Me.TextBox1.Text .ContentBodyNode.Text = Me.TextBox2.Text .ContentClosingNode.Text = Me.ComboBox2.Text & vbCrLf _ & vbCrLf & vbCrLf & .AddressAuthorNode.Text

End With

'Clear data out of the controls. Me.ComboBox1.Text = "" Me.ComboBox2.Text = "" Me.TextBox1.Text = "" Me.TextBox2.Text = ""

End Sub

4. Press F5 to run the code.

Figure 5.13 shows the data from ActionsPaneControl1 already inserted into the document, and ActionsPaneControl2 is visible on the task pane, ready to be filled in.

You might want to consider extending the functionality of your customized task pane. For example, you might want to bind the author list to a data source that contains employee names, or integrate the Outlook address book with the Addressee text box. This technique makes it easy for users to locate and insert the existing information rather than having to type it in a text box.

Figure 5.13. Populating a document with data on the actions pane
0 0

Post a comment