Table Of Contents

Previous topic

DataViewColumnFlags

Next topic

DataViewEvent

This Page

phoenix_title DataViewCtrl

DataViewCtrl is a control to display data either in a tree like fashion or in a tabular form or both.

If you only need to display a simple tree structure with an API more like the older TreeCtrl class, then the specialized DataViewTreeCtrl can be used. Likewise, if you only want to display simple table structure you can use the specialized DataViewListCtrl class. Both DataViewTreeCtrl and DataViewListCtrl can be used without defining your own DataViewModel.

A DataViewItem is used to represent a (visible) item in the control.

Unlike ListCtrl, DataViewCtrl doesn’t get its data from the user through virtual functions or by setting it directly. Instead you need to write your own DataViewModel and associate it with this control. Then you need to add a number of DataViewColumn to this control to define what each column shall display. Each DataViewColumn in turn owns 1 instance of a DataViewRenderer to render its cells.

A number of standard renderers for rendering text, dates, images, toggle, a progress bar etc. are provided. Additionally, the user can write custom renderers deriving from DataViewCustomRenderer for displaying anything.

All data transfer from the control to the model and the user code is done through Variant which can be extended to support more data formats as necessary. Accordingly, all type information uses the strings returned from Variant.GetType .

styles Window Styles

This class supports the following styles:

  • DV_SINGLE: Single selection mode. This is the default.
  • DV_MULTIPLE: Multiple selection mode.
  • DV_ROW_LINES: Use alternating colours for rows if supported by platform and theme. Currently only supported by the native GTK and OS X implementations but not by the generic one.
  • DV_HORIZ_RULES: Display fine rules between row if supported.
  • DV_VERT_RULES: Display fine rules between columns is supported.
  • DV_VARIABLE_LINE_HEIGHT: Allow variable line heights. This can be inefficient when displaying large number of items.
  • DV_NO_HEADER: Do not show column headers (which are shown by default).

events Events Emitted by this Class

Handlers bound for the following event types will receive a DataViewEvent parameter.

  • EVT_DATAVIEW_SELECTION_CHANGED: Process a wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED event.
  • EVT_DATAVIEW_ITEM_ACTIVATED: Process a wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED event. This event is triggered by float clicking an item or pressing some special key (usually “Enter”) when it is focused.
  • EVT_DATAVIEW_ITEM_START_EDITING: Process a wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING event. This event can be vetoed in order to prevent editing on an item by item basis.
  • EVT_DATAVIEW_ITEM_EDITING_STARTED: Process a wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED event.
  • EVT_DATAVIEW_ITEM_EDITING_DONE: Process a wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE event.
  • EVT_DATAVIEW_ITEM_COLLAPSING: Process a wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING event.
  • EVT_DATAVIEW_ITEM_COLLAPSED: Process a wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED event.
  • EVT_DATAVIEW_ITEM_EXPANDING: Process a wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING event.
  • EVT_DATAVIEW_ITEM_EXPANDED: Process a wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED event.
  • EVT_DATAVIEW_ITEM_VALUE_CHANGED: Process a wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED event.
  • EVT_DATAVIEW_ITEM_CONTEXT_MENU: Process a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU event generated when the user right clicks inside the control. Notice that this menu is generated even if the click didn’t occur on any valid item, in this case DataViewEvent.GetItem() simply returns an invalid item.
  • EVT_DATAVIEW_COLUMN_HEADER_CLICK: Process a wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK event.
  • EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK: Process a wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED event.
  • EVT_DATAVIEW_COLUMN_SORTED: Process a wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED event.
  • EVT_DATAVIEW_COLUMN_REORDERED: Process a wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED event.
  • EVT_DATAVIEW_ITEM_BEGIN_DRAG: Process a wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG event.
  • EVT_DATAVIEW_ITEM_DROP_POSSIBLE: Process a wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE event.
  • EVT_DATAVIEW_ITEM_DROP: Process a wxEVT_COMMAND_DATAVIEW_ITEM_DROP event.
Notice that this control doesn’t allow to process generic mouse events such as
wxEVT_LEFT_DOWN in all ports (notably it doesn’t work in wxGTK). If you need to handle any mouse events not covered by the ones above, consider using a custom renderer for the cells that must handle them.

class_hierarchy Inheritance Diagram

Inheritance diagram for class DataViewCtrl

Inheritance diagram of DataViewCtrl


appearance Control Appearance


wxMSW

wxMSW

wxMAC

wxMAC

wxGTK

wxGTK


sub_classes Known Subclasses

DataViewListCtrl, DataViewTreeCtrl


method_summary Methods Summary

__init__ Default Constructor.
AppendBitmapColumn Appends a column for rendering a bitmap.
AppendColumn Appends a DataViewColumn to the control.
AppendDateColumn Appends a column for rendering a date.
AppendIconTextColumn Appends a column for rendering text with an icon.
AppendProgressColumn Appends a column for rendering a progress indicator.
AppendTextColumn Appends a column for rendering text.
AppendToggleColumn Appends a column for rendering a toggle.
AssociateModel Associates a DataViewModel with the control.
ClearColumns Removes all columns.
Collapse Collapses the item.
Create Create the control.
DeleteColumn Deletes given column.
EditItem Programmatically starts editing given cell of item.
EnableDragSource Enable drag operations using the given format.
EnableDropTarget Enable drop operations using the given format.
EnsureVisible Call this to ensure that the given item is visible.
Expand Expands the item.
ExpandAncestors Expands all ancestors of the item.
GetColumn Returns pointer to the column.
GetColumnCount Returns the number of columns.
GetColumnPosition Returns the position of the column or -1 if not found in the control.
GetCurrentColumn Returns the column that currently has focus.
GetCurrentItem Returns the currently focused item.
GetExpanderColumn Returns column containing the expanders.
GetIndent Returns indentation.
GetItemRect Returns item rectangle.
GetModel Returns pointer to the data model associated with the control (if any).
GetSelectedItemsCount Returns the number of currently selected items.
GetSelection Returns first selected item or an invalid item if none is selected.
GetSelections Fills sel with currently selected items and returns their number.
GetSortingColumn Returns the DataViewColumn currently responsible for sorting or None if none has been selected.
HasSelection Returns True if any items are currently selected.
HitTest Hittest.
InsertColumn Inserts a DataViewColumn to the control.
IsExpanded Return True if the item is expanded.
IsSelected Return True if the item is selected.
PrependColumn Prepends a DataViewColumn to the control.
Select Select the given item.
SelectAll Select all items.
SetCurrentItem Changes the currently focused item.
SetExpanderColumn Set which column shall contain the tree-like expanders.
SetIndent Sets the indentation.
SetRowHeight Sets the row height.
SetSelections Sets the selection to the array of DataViewItems.
Unselect Unselect the given item.
UnselectAll Unselect all item.

api Class API



class DataViewCtrl(Control)

DataViewCtrl is a control to display data either in a tree like fashion or in a tabular form or both.

Possible constructors:

DataViewCtrl()

DataViewCtrl(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize,
             style=0, validator=DefaultValidator, name=DataViewCtrlNameStr)

Methods



__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Default Constructor.



__init__ (self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=0, validator=DefaultValidator, name=DataViewCtrlNameStr)

Constructor.

Calls Create .

Parameters:
  • parent (Window) –
  • id (int) –
  • pos (Point) –
  • size (Size) –
  • style (long) –
  • validator (Validator) –
  • name (string) –





AppendBitmapColumn(self, *args, **kw)

Appends a column for rendering a bitmap.

Returns the DataViewColumn created in the function or None on failure.


overload Overloaded Implementations:



AppendBitmapColumn (self, label, model_column, mode=DATAVIEW_CELL_INERT, width=-1, align=ALIGN_CENTER, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (string) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn



AppendBitmapColumn (self, label, model_column, mode=DATAVIEW_CELL_INERT, width=-1, align=ALIGN_CENTER, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (Bitmap) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn





AppendColumn(self, col)

Appends a DataViewColumn to the control.

Returns True on success.

Note that there is a number of short cut methods which implicitly create a DataViewColumn and a DataViewRenderer for it (see below).

Parameters:col (dataview.DataViewColumn) –
Return type:bool


AppendDateColumn(self, *args, **kw)

Appends a column for rendering a date.

Returns the DataViewColumn created in the function or None on failure.

Note

The align parameter is applied to both the column header and the column renderer.


overload Overloaded Implementations:



AppendDateColumn (self, label, model_column, mode=DATAVIEW_CELL_ACTIVATABLE, width=-1, align=ALIGN_NOT, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (string) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn



AppendDateColumn (self, label, model_column, mode=DATAVIEW_CELL_ACTIVATABLE, width=-1, align=ALIGN_NOT, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (Bitmap) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn





AppendIconTextColumn(self, *args, **kw)

Appends a column for rendering text with an icon.

Returns the DataViewColumn created in the function or None on failure. This method uses the DataViewIconTextRenderer class.

Note

The align parameter is applied to both the column header and the column renderer.


overload Overloaded Implementations:



AppendIconTextColumn (self, label, model_column, mode=DATAVIEW_CELL_INERT, width=-1, align=ALIGN_NOT, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (string) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn



AppendIconTextColumn (self, label, model_column, mode=DATAVIEW_CELL_INERT, width=-1, align=ALIGN_NOT, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (Bitmap) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn





AppendProgressColumn(self, *args, **kw)

Appends a column for rendering a progress indicator.

Returns the DataViewColumn created in the function or None on failure.

Note

The align parameter is applied to both the column header and the column renderer.


overload Overloaded Implementations:



AppendProgressColumn (self, label, model_column, mode=DATAVIEW_CELL_INERT, width=80, align=ALIGN_CENTER, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (string) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn



AppendProgressColumn (self, label, model_column, mode=DATAVIEW_CELL_INERT, width=80, align=ALIGN_CENTER, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (Bitmap) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn





AppendTextColumn(self, *args, **kw)

Appends a column for rendering text.

Returns the DataViewColumn created in the function or None on failure.

Note

The align parameter is applied to both the column header and the column renderer.


overload Overloaded Implementations:



AppendTextColumn (self, label, model_column, mode=DATAVIEW_CELL_INERT, width=-1, align=ALIGN_NOT, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (string) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn



AppendTextColumn (self, label, model_column, mode=DATAVIEW_CELL_INERT, width=-1, align=ALIGN_NOT, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (Bitmap) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn





AppendToggleColumn(self, *args, **kw)

Appends a column for rendering a toggle.

Returns the DataViewColumn created in the function or None on failure.

Note

The align parameter is applied to both the column header and the column renderer.


overload Overloaded Implementations:



AppendToggleColumn (self, label, model_column, mode=DATAVIEW_CELL_INERT, width=30, align=ALIGN_CENTER, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (string) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn



AppendToggleColumn (self, label, model_column, mode=DATAVIEW_CELL_INERT, width=30, align=ALIGN_CENTER, flags=DATAVIEW_COL_RESIZABLE)

Parameters:
  • label (Bitmap) –
  • model_column (int) –
  • mode (DataViewCellMode) –
  • width (int) –
  • align (Alignment) –
  • flags (int) –
Return type:

DataViewColumn





AssociateModel(self, model)

Associates a DataViewModel with the control.

This increases the reference count of the model by 1.

Parameters:model (dataview.DataViewModel) –
Return type:bool


ClearColumns(self)

Removes all columns.

Return type:bool


Collapse(self, item)

Collapses the item.

Parameters:item (dataview.DataViewItem) –


Create(self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=0, validator=DefaultValidator, name=DataViewCtrlNameStr)

Create the control.

Useful for two step creation.

Parameters:
  • parent (Window) –
  • id (int) –
  • pos (Point) –
  • size (Size) –
  • style (long) –
  • validator (Validator) –
  • name (string) –
Return type:

bool



DeleteColumn(self, column)

Deletes given column.

Parameters:column (dataview.DataViewColumn) –
Return type:bool


EditItem(self, item, column)

Programmatically starts editing given cell of item.

Doesn’t do anything if the item or this column is not editable.

Parameters:

New in version 2.9.4.

Note

Currently not implemented in OSX/Carbon.



EnableDragSource(self, format)

Enable drag operations using the given format.

Parameters:format (DataFormat) –
Return type:bool


EnableDropTarget(self, format)

Enable drop operations using the given format.

Parameters:format (DataFormat) –
Return type:bool


EnsureVisible(self, item, column=None)

Call this to ensure that the given item is visible.

Parameters:


Expand(self, item)

Expands the item.

Parameters:item (dataview.DataViewItem) –


ExpandAncestors(self, item)

Expands all ancestors of the item.

This method also ensures that the item itself as well as all ancestor items have been read from the model by the control.

Parameters:item (dataview.DataViewItem) –


GetColumn(self, pos)

Returns pointer to the column.

pos refers to the position in the control which may change after reordering columns by the user.

Parameters:pos (int) –
Return type: DataViewColumn


GetColumnCount(self)

Returns the number of columns.

Return type:int


GetColumnPosition(self, column)

Returns the position of the column or -1 if not found in the control.

Parameters:column (dataview.DataViewColumn) –
Return type:int


GetCurrentColumn(self)

Returns the column that currently has focus.

If the focus is set to individual cell within the currently focused item (as opposed to being on the item as a whole), then this is the column that the focus is on.

Returns None if no column currently has focus.

Return type: DataViewColumn

New in version 2.9.4.

See also

GetCurrentItem



GetCurrentItem(self)

Returns the currently focused item.

This is the item that the keyboard commands apply to. It may be invalid if there is no focus currently.

This method is mostly useful for the controls with DV_MULTIPLE style as in the case of single selection it returns the same thing as GetSelection .

Notice that under all platforms except Mac OS X the currently focused item may be selected or not but under OS X the current item is always selected.

Return type: DataViewItem

New in version 2.9.2.



GetExpanderColumn(self)

Returns column containing the expanders.

Return type: DataViewColumn


GetIndent(self)

Returns indentation.

Return type:int


GetItemRect(self, item, col=None)

Returns item rectangle.

This method is currently not implemented at all in wxGTK and only implemented for not None col argument in wxOSX. It is fully implemented in the generic version of the control.

Parameters:
  • item (dataview.DataViewItem) – A valid item.
  • col (dataview.DataViewColumn) – If not None, the rectangle returned corresponds to the intersection of the item with the specified column. If None, the rectangle spans all the columns.
Return type:

Rect



GetModel(self)

Returns pointer to the data model associated with the control (if any).

Return type: DataViewModel


GetSelectedItemsCount(self)

Returns the number of currently selected items.

This method may be called for both the controls with single and multiple selections and returns the number of selected item, possibly 0, in any case.

Return type:int

New in version 2.9.3.



GetSelection(self)

Returns first selected item or an invalid item if none is selected.

This method may be called for both the controls with single and multiple selections but returns an invalid item if more than one item is selected in the latter case, use HasSelection to determine if there are any selected items when using multiple selection.

Return type: DataViewItem


GetSelections(self, sel)

Fills sel with currently selected items and returns their number.

This method may be called for both the controls with single and multiple selections. In the single selection case it returns the array with at most one element in it.

Parameters:sel (DataViewItemArray) –
Return type:int


GetSortingColumn(self)

Returns the DataViewColumn currently responsible for sorting or None if none has been selected.

Return type: DataViewColumn


HasSelection(self)

Returns True if any items are currently selected.

This method may be called for both the controls with single and multiple selections.

Calling this method is equivalent to calling GetSelectedItemsCount and comparing its result with 0 but is more clear and might also be implemented more efficiently in the future.

Return type:bool

New in version 2.9.3.



HitTest(self, point, item, col)

Hittest.

Parameters:


InsertColumn(self, pos, col)

Inserts a DataViewColumn to the control.

Returns True on success.

Parameters:
Return type:

bool



IsExpanded(self, item)

Return True if the item is expanded.

Parameters:item (dataview.DataViewItem) –
Return type:bool


IsSelected(self, item)

Return True if the item is selected.

Parameters:item (dataview.DataViewItem) –
Return type:bool


PrependColumn(self, col)

Prepends a DataViewColumn to the control.

Returns True on success.

Note that there is a number of short cut methods which implicitly create a DataViewColumn and a DataViewRenderer for it.

Parameters:col (dataview.DataViewColumn) –
Return type:bool


Select(self, item)

Select the given item.

In single selection mode this changes the (unique) currently selected item. In multi selection mode, the item is selected and the previously selected items remain selected.

Parameters:item (dataview.DataViewItem) –


SelectAll(self)

Select all items.



SetCurrentItem(self, item)

Changes the currently focused item.

The item parameter must be valid, there is no way to remove the current item from the control.

In single selection mode, calling this method is the same as calling Select and is thus not very useful. In multiple selection mode this method only moves the current item however without changing the selection except under OS X where the current item is always selected, so calling SetCurrentItem selects item if it hadn’t been selected before.

Parameters:item (dataview.DataViewItem) –

New in version 2.9.2.

See also

GetCurrentItem



SetExpanderColumn(self, col)

Set which column shall contain the tree-like expanders.

Parameters:col (dataview.DataViewColumn) –


SetIndent(self, indent)

Sets the indentation.

Parameters:indent (int) –


SetRowHeight(self, rowHeight)

Sets the row height.

This function can only be used when all rows have the same height, i.e. when DV_VARIABLE_LINE_HEIGHT flag is not used.

Currently this is implemented in the generic and native GTK versions only and nothing is done (and False returned) when using OS X port.

Also notice that this method can only be used to increase the row height compared with the default one (as determined by the return value of DataViewRenderer.GetSize()), if it is set to a too small value then the minimum required by the renderers will be used.

Parameters:rowHeight (int) –
Return type:bool
Returns:True if the line height was changed or False otherwise.

New in version 2.9.2.



SetSelections(self, sel)

Sets the selection to the array of DataViewItems.

Parameters:sel (DataViewItemArray) –


Unselect(self, item)

Unselect the given item.

Parameters:item (dataview.DataViewItem) –


UnselectAll(self)

Unselect all item.

This method only has effect if multiple selections are allowed.


Properties



ColumnCount

See GetColumnCount



CurrentColumn

See GetCurrentColumn



CurrentItem

See GetCurrentItem and SetCurrentItem



ExpanderColumn

See GetExpanderColumn and SetExpanderColumn



Indent

See GetIndent and SetIndent



Model

See GetModel



SelectedItemsCount

See GetSelectedItemsCount



Selection

See GetSelection



SortingColumn

See GetSortingColumn