Item properties

There are a number of getter and setter methods that allow you to specify a part of an item. For the most part, these methods work on the first column of a row. To get at other columns, you might need to get the entire item using Getltem() and then use getter and setter methods of the item class. You can set the image for an item using SetItemImage(item, image, sellmage), where the item parameter is the index of the item in the list, and image and sellmage are both indexes into the image list, indicating the regular image and the image when selected, respectively. You can get or set the text of an item by using GetltemText(item) and Set-ItemText(item, text).

You can get or set the state of an individual item using GetltemState(item, stateMask) and SetItemState(item, state, stateMask). In this case, state and stateMask come from the values described in table 13.3. The state parameter (and the return value of the getter) is the actual state of the item, the stateMask is a mask of all possible values of current interest.

You can get a specific column with GetColumn(col), which returns the wx.List-Item instance for the column at the index col—meaning the header item for the

Table 13.3 Parameters for the state mask




The item is being cut. This state is only available under MS Windows.


The state doesn't matter. This state is only available under MS Windows.


The item is highlighted because it is receiving a drop from a drag & drop. This state is only available under MS Windows.


The item has the cursor focus.


The item is currently selected.

column. You can also set a column that has already been added using the method SetColumn(col, item). You can programmatically get the width of a column using GetColumnWidth(col), which returns the list width in pixels—obviously this is only useful for a list in report mode. You can set the column width using SetColumn-Width(col, width). The width is either the integer width or one of the special values wx.list_autosize, which sets the width to that of the longest item, or wx.list_autosize_useheader, which will set the width to that of the header text. Under non-Windows operating systems wx.LIST_AUTOSIZE_USEHEADER may just automatically set the column width to 80 pixels.

If you are getting confused about the indexes you've already added, you can query the list for the number of items already in it. The method GetColumn-Count() returns the number of columns defined in the list, and the method Get-ItemCount() returns the number of rows. If your list is in list mode, then the method GetCountPerPage() returns the number of items in each column.

To delete items from the list, use DeleteItem(item), which takes the index of the item in the list. If you want to zap all the items at once, use DeleteAllItems(), or ClearAll(), both of which will manage the trick. You can delete a column with DeleteColumn(col), which takes the column index of the doomed column.

Was this article helpful?

0 0

Post a comment