Programmer's Reference

Single selection lists

In the following example, the list widget shown at right is created with its selection policy set to XmSINGLESELECT. A single selection callback is added, to correspond with the selection policy.

| items shell list |
items := #('item1' 'item2' 'item3' 'item4' 'item5').
 
shell := CwTopLevelShell
   createApplicationShell: 'shell'
   argBlock: nil.
 

List widget

list := shell
   createList: 'list'
   argBlock: [:w |
      w
         selectionPolicy: XmSINGLESELECT;
         items: items].
list
   addCallback: XmNsingleSelectionCallback
   receiver: self
   selector: #singleSelect:clientData:callData:
   clientData: nil.
list manageChild.
 
shell realizeWidget.

The call data of the singleSelection callback specifies the item that was selected. The callback method below prints the entire callback data on the transcript. All components of the call data can be retrieved using the corresponding accessor method.

singleSelect: widget clientData: clientData callData: callData
   "Print the call data."
   Transcript cr; show: 'Single selection call data: ',
       callData printString

If Item 2 is selected, as in the illustration, the transcript output is as follows:

Single selection call data: CwListCallbackData(
  reason -> 23
  item -> 'Item 2'
  itemPosition -> 2
"These three fields of the callback data are only used for multiple
 and extended select lists."
  selectedItems -> nil
  selectedItemCount -> nil
  selectedItemPositions -> nil)


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]