ListSelection

Description

Returns the database ID of a highlighted record within your listview control.

Note: This function is for COM only. It is not available for Perl, and it is only available in the HCL Compass for Windows™ client.

You can use this property in response to a button click event (that is, the AD_BUTTON_CLICK event type) to find out what value is selected in a parent/child list box. The methods returns the primary key of the referenced record type.

In order to get a list selection, you must associate your button with the list control (such as a parent child control) that you want to be able to select an item from. You must also select the List View type Other. Then, when you press the button the value returned is the key of the referenced record (parts of multipart keys are separated by spaces).

Syntax

VBScript


eventObject.ListSelection 
Identifier
Description
eventObject
An instance of EventObject.
Return value
Returns a Variant array containing a single String value (or an empty array if no selection is made). The value returned contains the key of the referenced record (parts of multipart keys are separated by spaces).

Examples

VBScript


' The following script is invoked  when a user presses a button named "Select" 
' that is associated with a ListView control and performs an action of type
' "Other" (on the extended properties tab)):

   Function Defect_Cust_Sel(param)

      ' param As Variant

      Dim ListSel, Sel

      On Error Resume Next

      ListSel = param.ListSelection

      Sel = ListSel(0)

      SetFieldValue "Customer", Sel

   End Function



' The following example checks for event type, session type, and whether or
' not something is selected:

   Function MyRecordHook(param)

    ' param As Variant

     ' record type name isMyRecord

      Dim ListSel

      Dim Item

      ' Check if it is an event which you can have a selection for

      if param.eventtype = AD_BUTTON_CLICK then

      ' Make sure you aren't on the web since ListSelection doesn't work 
there

         if not GetSession.HasValue("_CQ_WEB_SESSION") then

            ' OK we're not on the web. Now check to see if anything is 
selected

            ListSel = param.ListSelection

            if ubound(ListSel) < lbound(ListSel) then

               ' Nothing is selected

            else

               Item = ListSel(0)

               ' ListSel is an array of strings with one element when 
               ' something is selected
                ' and no elements when nothing is selected

               ' Put your code here to do what you need to do

               msgbox "Selected item was:" & Item

            end if

         else

            ' Web interface, ListSelection API call doesn't work here

         end if

      else

         ' Its not a button click event, listselection only works with
         ' button click events

      end if

   End Function