How can I respond to a user selection in a list

Like other controls, a list control triggers events in response to user actions. You can set handlers for these events using the Bind() method, as discussed in chapter 3. All of these event handlers receive an instance of wx.ListEvent, which is a subclass of wx.CommandEvent. The wx.ListEvent has a few getter methods specific to its class. Some of the properties are only valid for specific event types described in other sections of this chapter. The properties common to all event types are described in table 13.4.

Table 13.4 Properties of wx.ListEvent

Property

Description

GetData()

The user data item associated with the list item for the event

GetKeyCode()

In a keypress event, the key code for the key pressed

GetIndex()

The index of the affected item within the list

GetItem()

The actual wx.Listltem affected by the event

GetImage()

The image in the cell affected by the event

GetMask()

The bit mask in the cell affected by the event

GetPoint()

The actual mouse position of the event

GetText()

The text in the cell affected by the event

There are several different event types for wx.ListEvent, each of which can be given a different handler. Some of the events are discussed in later sections where they are more relevant. Table 13.5 lists all of the event types dealing with selecting items in the list.

Table 13.5 Event types for selecting items in a list control

Event Type

Description

EVT_LIST_BEGIN_DRAG

Triggered when the user begins a drag operation with the left mouse button

EVT_LIST_BEGIN_RDRAG

Triggered when the user begins a drag operation with the right mouse button

EVT_LIST_DELETE_ALL_ITEMS

Triggered by a call to a DeleteAll() method of the list

EVT_LIST_DELETE_ITEM

Triggered by a call to a Delete() method of the list

EVT_LIST_INSERT_ITEM

Triggered when an item is inserted into the list

EVT_LIST_ITEM_ACTIVATED

The item has been activated, by a user pressing enter or double click while the item is selected

Table 13.5 Event types for selecting items in a list control (continued)

Event Type

Description

EVT_LIST_ITEM_DESELECTED

Triggered when the item loses the user selection

EVT_LIST_ITEM_FOCUSED

Triggered when the item with the focus changes

EVT_USTJTEM_MIDDLE_CUCK

Triggered when the middle mouse button is clicked on the list

EVT_USTJTEM_RIGHT_CUCK

Triggered when the right mouse button is clicked on the list

EVT_LIST_ITEM_SELECTED

Triggered when an item is selected with a left mouse click

EVT_LIST_ITEM_KEY_DOWN

Triggered when a key is pressed while the list control has the focus

Listing 13.3 will provide examples of many of these event types in a running program.

Was this article helpful?

0 0

Post a comment