Exercise 12: Explore the Event Handler Base Class
Step 1 - Go to definition.
-
A quick way to gain visibility into the base class is to right-click the class we are inheriting and select Go To Definition from the popup menu which opens up the Object Browser.
Figure: Use the object browser to investigate what is possible within a batch handler
Below, we see the Object Browser for the BatchEntryHandler class that we inherit with our custom batch event handler.
Figure: Object browser
-
Check out some of the events within the BatchEntryHandler. We can tap into an event from this class by authoring a method with the same signature as the event we are handling and include the Handles <sender>.<event> after the arguments for the method. For example, the BatchEntryHandler contains the LeaveCell event.
Figure: LeaveCell Event
In our custom event handler, we can handle this event by authoring an event handler within our FoodItemAddBatchEventHandler class with the following signature:
Private Sub FoodItemAddBatch_LeaveCell(ByVal sender As Object, ByVal e As Browser.Batch.BatchLeaveCellEventArgs) Handles Me.LeaveCell End Sub
Notice how the types used within the sender and e arguments within our handler match the arguments within the event we are handling.
Handle the BatchEntryHandler LeaveCell Event
Let’s continue exploring what can be done with the LeaveCell event that fires every time a user leaves a cell within the batch UI grid.
Step 2 - Handle the LeaveCell event.
-
Using the event handler sub routine that we created in Exercise 12: Exploring the Event Handler Base Class, explore what is inside the BatchLeaveCellEventArgs that get passed to our handler when the LeaveCell event fires. Below we can see the event handler.
Private Sub FoodItemAddBatch_LeaveCell(ByVal sender As Object, ByVal e As Browser.Batch.BatchLeaveCellEventArgs) Handles Me.LeaveCell End Sub
Within the BatchLeaveCellEventArgs type that is declared with a variable named "e," you can see which row you were on via e.Row. You can view which column you just left via e.Column. You can see the value within the cell you left via e.Value. By grabbing the DataFormItem (Blackbaud.AppFx.XmlTypes.DataForms.DataFormItem) using the base class's GetRow function and passing e.row you can determine the Field ID of the cell you left.
-
Add the following code to your event handler.
Private Sub FoodItemAddBatch_LeaveCell(ByVal sender As Object, ByVal e As Browser.Batch.BatchLeaveCellEventArgs) Handles Me.LeaveCell Dim dfi As DataFormItem dfi = Me.GetRow(e.Row) MsgBox("Row#= " & e.Row & " Column#= " & e.Column & " Column Name= " & dfi.Values(e.Column).ID & " Value=" & e.Value.ToString) End Sub
Step 3 - Rebuild and redeploy the code changes.
-
Build the new Blackbaud.CustomFx.FoodBank.Client assembly.
-
With the Blackbaud.CustomFx.FoodBank.Client.dll built, copy the file into the Infinity application server's \bbappfx\vroot\browser\clientbin\custom folder.
-
Open a batch, modify or add a row, and leave a cell. The new message box should appear.
Figure: New LeaveCell event handler