ConnectListViewNotify

>>-aMessageExtensions~ConnectListViewNotify(--id--,--------------------->

>--"--+-CLICK--------------+--"--+---------------+--)-----------------><
      +-CHECKBOXCHANGED----+     +-,--methodName-+
      +-SELECTCHANGED------+
      +-FOCUSCHANGED-------+
      +-SELECTFOCUSCHANGED-+

Microsoft continually enhances the Windows User Interface and therefore the dialog controls evolve over time. The ConnectListViewNotify method is similar to the ConnectListNotify method, but it is designed to take advantage of new features in the list-view control. It connects notification message sent by a list view control to its parent dialog with a method, provided by the programmer, in an ooDialog class. These notifications inform the dialog that an event has occurred in the list view.

The ConnectListViewNotify method is designed to provide more information to the invoked method than the ConnectListNotify or ConnectCommonNotify methods. Connecting an event through the ConnectListViewNotify method is used as a replacement for connecting the same event through the ConnectListNotify method or the ConnectCommonNotify method.

Note: If the same event, for the same control, is connected using two different ConnectXXX methods, only one connection will be in effect. This will be the connection whose ConnectXXX method is invoked first. For example, take a dialog that has a list view control with resource ID of 109. If the mouse click event is connected for that control using the ConnectCommonNotify method and then the mouse click event is also connected using the ConnectListViewNotify method, only one connection will be active. Which one is active is dependent on the order of invocation of the ConnectXXX methods.

Each of the events that can be connected through the ConnectListViewNotify method is a replacement for connecting that event through one of the other ConnectXXX methods. The argument documentation provides more detail on this.

Arguments:

The arguments are:

id

The ID of the list view control for which the event is to be connected to a method.

event

The event to be connected with a method:

Note: When using ConnectListViewNotify a separate method can be connected to each of the checkbox changed, selection changed, and focus changed events. These event connectionss are all replacements for the ConnectListNotify method's CHANGED event.

CLICK

An item was clicked with the left mouse button. Connecting the CLICK event is a replacement for the ConnectCommonNotify method's CLICK event.

CHECKBOXCHANGED

The check box state of an item changed. (The check box was checked or unchecked.) This event can only occur if the list view has the check box extended list view style.

SELECTCHANGED

The selection state of an item changed. (The item was selected or unselected.)

FOCUSCHANGED

The focus state of an item changed. (The item gained or lost the focus.)

SELECTFOCUSCHANGED

The selection state or the focus state of an item changed. This event argument combines the selection changed and the focus changed event into one connection. When this event is connected, separate selection changed and focus changed events can not be connected. This keyword can be abbreviated to "SELECTFOCUS".

methodName

The method that is to be invoked whenever the specified event occurs. Provide a method with a matching name in the dialog class. If you omit this argument, a default method name will be constructed. This name will be the name of the event preceded by On.

Return value:

The return codes are:

0

No error detected.

-1

The resource ID could not be resolved or the event argument is incorrect.

1

The event was not connected correctly to a method.

Event Methods

The following details the method signature for each of the ConnectListViewNotify events:

CLICK

The method invoked for the left mouse click event recieves four arguments.

::method onClick
use arg id, itemIndex, columnIndex, keyState

id

The resource ID of the list view control whose item was clicked.

itemIndex

The index of the item that was clicked.

columnIndex

The index of the subitem that was clicked. This will be the column clicked on if the list view is in report view. In other views it will be 0.

keyState

This argument reports the state of the shift, control, and alt keys at the time of the mouse click. The argument is a string of keywords separated by blanks. The keywords consist of: SHIFT, CONTROL, ALT, or NONE. The presence of a keyword indicates the key was held down when the user clicked on the list view control. NONE of course indicates that none of the keys were down. If the user managed to hold all three of the keys down at the time of the mouse click, the argument would be the string: "SHIFT CONTROL ALT"

CHECKBOXCHANGED

The method invoked for the checkbox changed event recieves three arguments. The method signature will look as follows:

::method onCheckboxChanged
  use arg id, itemIndex, state

id

The resource ID of the list view control whose item had the checkbox state changed.

itemIndex

The index of the item whose checkbox was changed.

state

This argument reports whether the check box was checked or unchecked. Its value will be either "CHECKED" or "UNCHECKED"

SELECTCHANGE

The method invoked when the selection changes will recieve three arguments. The method signature will look as follows:

::method onSelectChanged
  use arg id, itemIndex, state

id

The resource ID of the list view control whose item had the selection changed.

itemIndex

The index of the item whose selection was changed.

state

This argument reports whether the item was selected or unselected. Its value will be either "SELECTED" or "UNSELECTED"

FOCUSCHANGED

The method invoked for the focus changed event recieves three arguments. The method signature will look as follows:

::method onFocusChanged
  use arg id, itemIndex, state

id

The resource ID of the list view control whose item had the focus changed.

itemIndex

The index of the item which gained or lost the focus.

state

This argument reports whether the focus was gained or lost. Its value will be either "FOCUSED" or "UNFOCUSED"

SELECTFOCUSCHANGED

The method invoked for the selection or focus changed event recieves three arguments. The method signature will look as follows:

::method onSelectFocusChanged
  use arg id, itemIndex, state

id

The resource ID of the list view control whose item had the either the focus or the selection changed.

itemIndex

The index of the item where the state was changed.

state

This argument reports whether the focus was gained or lost and whether the selection was gained or lost. Its value will contain at least one of the keywords: "SELECTED", "UNSELECTED", "FOCUSED" or "UNFOCUSED". It is possible for both the selection and focus changed to be reported at once, however sometimes each change is reported separately. (This has nothing to do with ooDialog, it is how the operating system sends the messages.)

Example:

The following example is from an address book application. A list view control is filled with the information from the address book, one item for each entry. The check box changed event is connected to the onCheckboxChanged method. The onCheckboxChanged method will receive 3 arguments: the resource ID of the control, the index of the item whose check box changed, and the changed state. If the user checks the check box, that entry is added to a mail merge being constructed. If the user unchecks the box, the entry is removed from the mail merge.

::class MailingListDlg subclass UserDialog inherit AdvancedControls MessageExtensions

::method initDialog
  expose mailList

  ...
  mailList = self~getListControl(IDC_LV_ADDRESSES)
  ...

  -- Since the methodName argument is omitted, ooDialog will construct a default
  -- name of 'onCheckboxChanged'
  self~connectListViewNotify(IDC_LV_ADDRESSES, "CHECKBOXCHANGED")
  ...

::method onCheckboxChanged
  expose mailList
  use arg id, itemIndex, state

  if state == "CHECKED" then
    self~addToMailMerge(mailList, itemIndex)
  else
    self~removeFromMailMerge(mailList, itemIndex)