Using a ListView Control to Select Trends to Display
Multiple trends can be viewed on a Trend Tool simultaneously. This functionality can allow the user to dynamically select one or more trends to view, if script is provided to do so. Several list controls could be used in this situation to display the set of values to trend, including a List Box, a set of Check Buttons, or any ActiveX list control.
The following example uses a Microsoft ListView Control (ActiveX) to take advantage of its option to show check boxes next to list items. It is assumed that the Site/Service and Facility are configured at the View level.
Using a ListView Control (ActiveX) to enable Display of Single or Multiple Trends
- Create a new Studio screen.
- Place a ListView control on the screen.
- Click the ActiveX tool
on the Standard Tools palette. - Click and drag the outline of the list box on the screen. When the mouse button is released, an Insert OLE Control dialog box appears.
- In the dialog box, select Microsoft ListView Control. The version number may be included in the name.
- Right-click the control to open its properties. In the (ObjectCode) field, type "listControl."
- Place a Trend control on the screen.
- Click the Trend *
on the Standard Tools palette. - Click and drag the outline of the Trend control on the screen.
- Right-click the control to open its properties. In the (ObjectCode) field, type "trendControl."
- Add general declarations.
- Open the Script Editor and navigate to (General), (Declarations).
- Enter the following script. Note that trend series are stored in a two dimensional array, where for each series, the list item, long point ID, and UDC, and axis number are stored in that order.
|
'(Declarations)
'Set up trend colors Dim trendColors(3) trendColors(0) = vbRed trendColors(1) = vbBlue trendColors(2) = vbGreen
'Initialize trend series array Dim SeriesArray(3,3)
'Method to add a series to the array and trend control Sub AddTrendSeries(longPointID, axisNum, listItem, udc) SeriesArray(axisNum, 0) = listItem SeriesArray(axisNum, 1) = longPointID SeriesArray(axisNum, 2) = udc SeriesArray(axisNum, 3) = axisNum
'Update trend control With trendControl .SiteService(axisNum) = TheView.SiteService .FacilityId(axisNum) = TheView.Facility .Udc(axisNum) = udc .AutoScale(axisNum) = True .OverlayYAxis(axisNum) = False .PointIdLong(axisNum) = longPointID .XAxisLabel = "Time" .SeriesColor(axisNum) = trendColors(axisNum) .LineType = 9 "Medium Thin Solid .Restart() End With End Sub
'End of (Declarations) |
- Add initialization script to the ListView Control.
- In the Script Editor, navigate to the listControl EventInitialize event.
- Enter the following script. Successive columns are defined as sub items of the first column. The second column (UDC) is used to store the UDC value for each item, and can be made invisible if desired.
|
Sub listControl_EventInitialize() Dim This : Set This = listControl This.Checkboxes = True This.View = 3 'Report view
'Add columns This.ColumnHeaders.Add , , "Choose one or more items to trend" This.ColumnHeaders.Add , , "UDC"
'Add descriptions in first column (changes these descriptions to match your application) With This.ListItems .Add , , "Vol Gas Today" .Add , , "Vol Gas Yest" .Add , , "Gas Rate" End With
'Add UDCs in second column (change to match your application) With This .ListItems(1).SubItems(1) = "VGT" .ListItems(2).SubItems(1) = "VGY" .ListItems(3).SubItems(1) = "RGAS" End With End Sub |
- Click OK to close the script editor.
- Add script to run when a user checks or unchecks an item in the ListView.
- Still in the Script Editor, navigate to the listControl EventItemCheck event.
- Enter the following script. This event has one parameter, Item, the list item that called the event after being checked or unchecked.
|
Sub listControl_EventItemCheck(Item) Dim This : Set This = listControl If Item.Checked = True Then longPointID = TheView.Facility & "_" & Item.SubItems For i = 0 To ubound(SeriesArray) If SeriesArray(i, 0) = "" Then 'Fill in first empty spot AddTrendSeries LongPointID, i, Item, Item.SubItems(1) Exit For End If Next Else 'Remove from series array For i = 0 To ubound(SeriesArray) If SeriesArray(i, 0) = Item Then trendControl.DeleteSeries(SeriesArray(i, 3)) SeriesArray(i, 0) = "" SeriesArray(i, 1) = "" SeriesArray(i, 2) = "" SeriesArray(i, 3) = "" Exit For End If Next ReIndexSeriesArray End if End Sub |
- Save the screen and switch to Run mode. Assuming that sufficient data values exist for the given UDCs, try turning series trends on and off to see the Trend control updated accordingly.


