.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2018 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.VListBox:

==========================================================================================================================================
|phoenix_title|  **wx.VListBox**
==========================================================================================================================================

:ref:`wx.VListBox`  is a ListBox-like control with the following two main differences from a regular :ref:`wx.ListBox`: it can have an arbitrarily huge number of items because it doesn't store them itself but uses the :meth:`~wx.VListBox.OnDrawItem`  callback to draw them (so it is a virtual listbox) and its items can have variable height as determined by :meth:`~wx.VListBox.OnMeasureItem`  (so it is also a listbox with the lines of variable height).          

Also, as a consequence of its virtual nature, it doesn't have any methods to append or insert items in it as it isn't necessary to do it: you just have to call :meth:`~wx.VListBox.SetItemCount`  to tell the control how many items it should display. Of course, this also means that you will never use this class directly because it has pure virtual functions, but will need to derive your own class from it (for example, :ref:`wx.html.HtmlListBox`). 

However it emits the same events as :ref:`wx.ListBox`  and the same event macros may be used with it. Since :ref:`wx.VListBox`  does not store its items itself, the events will only contain the index, not any contents such as the string of an item. 







         



.. seealso:: :ref:`wx.html.SimpleHtmlListBox`, :ref:`wx.html.HtmlListBox`    







|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>VListBox</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.VListBox_inheritance.png" alt="Inheritance diagram of VListBox" usemap="#dummy" class="inheritance"/></center>
   </div>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.VScrolledWindow.html" title="wx.VScrolledWindow" alt="" coords="105,315,253,344"/> <area shape="rect" id="node9" href="wx.VListBox.html" title="wx.VListBox" alt="" coords="131,392,228,421"/> <area shape="rect" id="node2" href="wx.Panel.html" title="wx.Panel" alt="" coords="70,237,145,267"/> <area shape="rect" id="node3" href="wx.VarVScrollHelper.html" title="wx.VarVScrollHelper" alt="" coords="179,237,327,267"/> <area shape="rect" id="node4" href="wx.Object.html" title="wx.Object" alt="" coords="5,5,87,35"/> <area shape="rect" id="node6" href="wx.EvtHandler.html" title="wx.EvtHandler" alt="" coords="48,83,159,112"/> <area shape="rect" id="node5" href="wx.Window.html" title="wx.Window" alt="" coords="59,160,148,189"/> <area shape="rect" id="node7" href="wx.VarScrollHelperBase.html" title="wx.VarScrollHelperBase" alt="" coords="173,160,344,189"/> <area shape="rect" id="node8" href="wx.Trackable.html" title="wx.Trackable" alt="" coords="112,5,213,35"/> </map> 
   </p>

|


|sub_classes| Known Subclasses
==============================

:ref:`wx.html.HtmlListBox`

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.VListBox.__init__`                                                    Default constructor, you must call :meth:`~VListBox.Create`   later.
:meth:`~wx.VListBox.Clear`                                                       Deletes all items from the control.
:meth:`~wx.VListBox.Create`                                                      Creates the control.
:meth:`~wx.VListBox.DeselectAll`                                                 Deselects all the items in the listbox.
:meth:`~wx.VListBox.GetClassDefaultAttributes`                                   
:meth:`~wx.VListBox.GetFirstSelected`                                            Returns the index of the first selected item in the listbox or  ``NOT_FOUND``   if no items are currently selected.
:meth:`~wx.VListBox.GetItemCount`                                                Get the number of items in the control.
:meth:`~wx.VListBox.GetItemRect`                                                 Returns the rectangle occupied by this item in physical coordinates.
:meth:`~wx.VListBox.GetMargins`                                                  Returns the margins used by the control.
:meth:`~wx.VListBox.GetNextSelected`                                             Returns the index of the next selected item or  ``NOT_FOUND``   if there are no more.
:meth:`~wx.VListBox.GetSelectedCount`                                            Returns the number of the items currently selected.
:meth:`~wx.VListBox.GetSelection`                                                Get the currently selected item or  ``NOT_FOUND``   if there is no selection.
:meth:`~wx.VListBox.GetSelectionBackground`                                      Returns the background colour used for the selected cells.
:meth:`~wx.VListBox.HasMultipleSelection`                                        Returns ``True`` if the listbox was created with  ``LB_MULTIPLE``   style and so supports multiple selection or ``False`` if it is a single selection listbox.
:meth:`~wx.VListBox.IsCurrent`                                                   Returns ``True`` if this item is the current one, ``False`` otherwise.
:meth:`~wx.VListBox.IsSelected`                                                  Returns ``True`` if this item is selected, ``False`` otherwise.
:meth:`~wx.VListBox.OnDrawBackground`                                            This method is used to draw the item's background and, maybe, a border around it.
:meth:`~wx.VListBox.OnDrawItem`                                                  The derived class must implement this function to actually draw the item with the given index on the provided DC.
:meth:`~wx.VListBox.OnDrawSeparator`                                             This method may be used to draw separators between the lines.
:meth:`~wx.VListBox.OnMeasureItem`                                               The derived class must implement this method to return the height of the specified item (in pixels).
:meth:`~wx.VListBox.Select`                                                      Selects or deselects the specified item which must be valid (i.e. not equal to  ``NOT_FOUND`` ).
:meth:`~wx.VListBox.SelectAll`                                                   Selects all the items in the listbox.
:meth:`~wx.VListBox.SelectRange`                                                 Selects all items in the specified range which may be given in any order.
:meth:`~wx.VListBox.SetItemCount`                                                Set the number of items to be shown in the control.
:meth:`~wx.VListBox.SetMargins`                                                  Set the margins: horizontal margin is the distance between the window border and the item contents while vertical margin is half of the distance between items.
:meth:`~wx.VListBox.SetSelection`                                                Set the selection to the specified item, if it is -1 the selection is unset.
:meth:`~wx.VListBox.SetSelectionBackground`                                      Sets the colour to be used for the selected cells background.
:meth:`~wx.VListBox.Toggle`                                                      Toggles the state of the specified `item`, i.e. selects it if it was unselected and deselects it if it was selected.
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.VListBox.ItemCount`                                                   See :meth:`~wx.VListBox.GetItemCount` and :meth:`~wx.VListBox.SetItemCount`
:attr:`~wx.VListBox.Margins`                                                     See :meth:`~wx.VListBox.GetMargins` and :meth:`~wx.VListBox.SetMargins`
:attr:`~wx.VListBox.SelectedCount`                                               See :meth:`~wx.VListBox.GetSelectedCount`
:attr:`~wx.VListBox.Selection`                                                   See :meth:`~wx.VListBox.GetSelection` and :meth:`~wx.VListBox.SetSelection`
:attr:`~wx.VListBox.SelectionBackground`                                         See :meth:`~wx.VListBox.GetSelectionBackground` and :meth:`~wx.VListBox.SetSelectionBackground`
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.VListBox(VScrolledWindow)

   **Possible constructors**::

       VListBox()
       
       VListBox(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize,
                style=0, name=VListBoxNameStr)
       
   
   VListBox is a ListBox-like control with the following two main
   differences from a regular ListBox: it can have an arbitrarily huge
   number of items because it doesn't store them itself but uses the
   OnDrawItem() callback to draw them (so it is a virtual listbox) and
   its items can have variable height as determined by OnMeasureItem()
   (so it is also a listbox with the lines of variable height).



   .. method:: __init__(self, *args, **kw)



      |overload| Overloaded Implementations:

      **~~~**

      
      **__init__** `(self)`
      
      Default constructor, you must call :meth:`Create`   later.                   
      
      
      
      
      **~~~**

      
      **__init__** `(self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=0, name=VListBoxNameStr)`
      
      Normal constructor which calls :meth:`Create`   internally.                  
      
      
      :param `parent`: 
      :type `parent`: wx.Window
      :param `id`: 
      :type `id`: wx.WindowID
      :param `pos`: 
      :type `pos`: wx.Point
      :param `size`: 
      :type `size`: wx.Size
      :param `style`: 
      :type `style`: long
      :param `name`: 
      :type `name`: string
      
      
      
      
      
      
      **~~~**






   .. method:: Clear(self)

      Deletes all items from the control.                   





   .. method:: Create(self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=0, name=VListBoxNameStr)

      Creates the control.                  

      To finish creating it you also should call :meth:`SetItemCount`   to let it know about the number of items it contains. 

      The only special style which may be used with :ref:`wx.VListBox`  is  ``LB_MULTIPLE``   which indicates that the listbox should support multiple selection. 

                


      :param `parent`: 
      :type `parent`: wx.Window
      :param `id`: 
      :type `id`: wx.WindowID
      :param `pos`: 
      :type `pos`: wx.Point
      :param `size`: 
      :type `size`: wx.Size
      :param `style`: 
      :type `style`: long
      :param `name`: 
      :type `name`: string




      :rtype: `bool`







      :returns: 

         ``True`` on success or ``False`` if the control couldn't be created.   








   .. method:: DeselectAll(self)

      Deselects all the items in the listbox.                  

      This method is only valid for multi selection listboxes. 

                

      :rtype: `bool`







      :returns: 

         ``True`` if any items were changed, i.e. if there had been any selected items before, or ``False`` if all the items were already deselected.  







      .. seealso:: :meth:`SelectAll` , :meth:`Select`     








   .. staticmethod:: GetClassDefaultAttributes(variant=WINDOW_VARIANT_NORMAL)




      :param `variant`: 
      :type `variant`: wx.WindowVariant




      :rtype: :ref:`wx.VisualAttributes`








   .. method:: GetFirstSelected(self)

      Returns the index of the first selected item in the listbox or  ``NOT_FOUND``   if no items are currently selected.                   

      `cookie`  is an opaque parameter which should be passed to the subsequent calls to :meth:`GetNextSelected` . It is needed in order to allow parallel iterations over the selected items. 

      Here is a typical example of using these functions: 

      ::

                  item, cookie = vlbox.GetFirstSelected()
                  while item != wx.NOT_FOUND:
                      # ... process item ...
                      item, cookie = vlbox.GetNextSelected(cookie)



      This method is only valid for multi selection listboxes.                  

      :rtype: `tuple`







      :returns: 

         ( `int`, `cookie` ) 








   .. method:: GetItemCount(self)

      Get the number of items in the control.                  

                

      :rtype: `int`







      .. seealso:: :meth:`SetItemCount`     








   .. method:: GetItemRect(self, item)

      Returns the rectangle occupied by this item in physical coordinates.                  

      If the item is not currently visible, returns an empty rectangle. 

                


      :param `item`: 
      :type `item`: int




      :rtype: :ref:`wx.Rect`







      .. versionadded:: 2.9.0 
     








   .. method:: GetMargins(self)

      Returns the margins used by the control.                  

      The  ``x``   field of the returned point is the horizontal margin and the   ``y``   field is the vertical one. 

                

      :rtype: :ref:`wx.Point`







      .. seealso:: :meth:`SetMargins`     








   .. method:: GetNextSelected(self, cookie)

      Returns the index of the next selected item or  ``NOT_FOUND``   if there are no more.                   

      This method is only valid for multi selection listboxes. 

                


      :param `cookie`: 
      :type `cookie`: long




      :rtype: `tuple`







      :returns: 

         ( `int`, `cookie` ) 







      .. seealso:: :meth:`GetFirstSelected`     








   .. method:: GetSelectedCount(self)

      Returns the number of the items currently selected.                  

      It is valid for both single and multi selection controls. In the former case it may only return 0 or 1 however. 

                

      :rtype: `int`







      .. seealso:: :meth:`IsSelected` , :meth:`GetFirstSelected` , :meth:`GetNextSelected`     








   .. method:: GetSelection(self)

      Get the currently selected item or  ``NOT_FOUND``   if there is no selection.                   

      :rtype: `int`








   .. method:: GetSelectionBackground(self)

      Returns the background colour used for the selected cells.                  

      By default the standard system colour is used. 

                

      :rtype: :ref:`wx.Colour`







      .. seealso:: :meth:`wx.SystemSettings.GetColour` , :meth:`SetSelectionBackground`     








   .. method:: HasMultipleSelection(self)

      Returns ``True`` if the listbox was created with  ``LB_MULTIPLE``   style and so supports multiple selection or ``False`` if it is a single selection listbox.                   

      :rtype: `bool`








   .. method:: IsCurrent(self, item)

      Returns ``True`` if this item is the current one, ``False`` otherwise.                  

      The current item is always the same as selected one for the single selection listbox and in this case this method is equivalent to :meth:`IsSelected`   but they are different for multi selection listboxes where many items may be selected but only one (at most) is current.                  


      :param `item`: 
      :type `item`: int




      :rtype: `bool`








   .. method:: IsSelected(self, item)

      Returns ``True`` if this item is selected, ``False`` otherwise.                  


      :param `item`: 
      :type `item`: int




      :rtype: `bool`








   .. method:: OnDrawBackground(self, dc, rect, n)

      This method is used to draw the item's background and, maybe, a border around it.                  

      The base class version implements a reasonable default behaviour which consists in drawing the selected item with the standard background colour and drawing a border around the item if it is either selected or current. 

                


      :param `dc`: 
      :type `dc`: wx.DC
      :param `rect`: 
      :type `rect`: wx.Rect
      :param `n`: 
      :type `n`: int






      .. todo:: Change this function signature to non-const.    








   .. method:: OnDrawItem(self, dc, rect, n)

      The derived class must implement this function to actually draw the item with the given index on the provided DC.                  




      :param `dc`: The device context to use for drawing.   
      :type `dc`: wx.DC
      :param `rect`: The bounding rectangle for the item being drawn (DC clipping region is set to this rectangle before calling this function).   
      :type `rect`: wx.Rect
      :param `n`: The index of the item to be drawn.  
      :type `n`: int








                  



      .. todo:: Change this function signature to non-const.    








   .. method:: OnDrawSeparator(self, dc, rect, n)

      This method may be used to draw separators between the lines.                  

      The rectangle passed to it may be modified, typically to deflate it a bit before passing to :meth:`OnDrawItem` . 

      The base class version of this method doesn't do anything. 




      :param `dc`: The device context to use for drawing.   
      :type `dc`: wx.DC
      :param `rect`: The bounding rectangle for the item.   
      :type `rect`: wx.Rect
      :param `n`: The index of the item.  
      :type `n`: int








                  



      .. todo:: Change this function signature to non-const.    








   .. method:: OnMeasureItem(self, n)

      The derived class must implement this method to return the height of the specified item (in pixels).                  


      :param `n`: 
      :type `n`: int




      :rtype: :ref:`wx.Coord`








   .. method:: Select(self, item, select=True)

      Selects or deselects the specified item which must be valid (i.e. not equal to  ``NOT_FOUND`` ).                   


      This function is only valid for the multiple selection listboxes, use  :meth:`SetSelection`   for the single selection ones.                  


      :param `item`: 
      :type `item`: int
      :param `select`: 
      :type `select`: bool




      :rtype: `bool`







      :returns: 

         ``True`` if the items selection status has changed or ``False`` otherwise.  








   .. method:: SelectAll(self)

      Selects all the items in the listbox.                  


      This method is only valid for multi selection listboxes.  

                

      :rtype: `bool`







      :returns: 

         ``True`` if any items were changed, i.e. if there had been any unselected items before, or ``False`` if all the items were already selected.  







      .. seealso:: :meth:`DeselectAll` , :meth:`Select`     








   .. method:: SelectRange(self, from_, to_)

      Selects all items in the specified range which may be given in any order.                  


      This method is only valid for multi selection listboxes.  

                


      :param `from_`: 
      :type `from_`: int
      :param `to_`: 
      :type `to_`: int




      :rtype: `bool`







      :returns: 

         ``True`` if the items selection status has changed or ``False`` otherwise.  







      .. seealso:: :meth:`SelectAll` , :meth:`Select`     








   .. method:: SetItemCount(self, count)

      Set the number of items to be shown in the control.                  

      This is just a synonym for :meth:`wx.VScrolledWindow.SetRowCount` .                  


      :param `count`: 
      :type `count`: int







   .. method:: SetMargins(self, *args, **kw)

      Set the margins: horizontal margin is the distance between the window border and the item contents while vertical margin is half of the distance between items.                  

      By default both margins are 0.                   


      |overload| Overloaded Implementations:

      **~~~**

      
      **SetMargins** `(self, pt)`
      
      
      
      
      :param `pt`: 
      :type `pt`: wx.Point
      
      
      
      
      
      
      **~~~**

      
      **SetMargins** `(self, x, y)`
      
      
      
      
      :param `x`: 
      :type `x`: int
      :param `y`: 
      :type `y`: int
      
      
      
      
      
      
      **~~~**






   .. method:: SetSelection(self, selection)

      Set the selection to the specified item, if it is -1 the selection is unset.                  

      The selected item will be automatically scrolled into view if it isn't currently visible. 

      This method may be used both with single and multiple selection listboxes.                  


      :param `selection`: 
      :type `selection`: int







   .. method:: SetSelectionBackground(self, col)

      Sets the colour to be used for the selected cells background.                  

      The background of the standard cells may be changed by simply calling :meth:`wx.Window.SetBackgroundColour` . 

                


      :param `col`: 
      :type `col`: wx.Colour






      .. note:: 

         Using a non-default background colour may result in control having an appearance different from the similar native controls and should be avoided in general.  







      .. seealso:: :meth:`GetSelectionBackground`     








   .. method:: Toggle(self, item)

      Toggles the state of the specified `item`, i.e. selects it if it was unselected and deselects it if it was selected.                  

      This method is only valid for multi selection listboxes. 

                


      :param `item`: 
      :type `item`: int






      .. seealso:: :meth:`Select`     








   .. attribute:: ItemCount

      See :meth:`~wx.VListBox.GetItemCount` and :meth:`~wx.VListBox.SetItemCount`


   .. attribute:: Margins

      See :meth:`~wx.VListBox.GetMargins` and :meth:`~wx.VListBox.SetMargins`


   .. attribute:: SelectedCount

      See :meth:`~wx.VListBox.GetSelectedCount`


   .. attribute:: Selection

      See :meth:`~wx.VListBox.GetSelection` and :meth:`~wx.VListBox.SetSelection`


   .. attribute:: SelectionBackground

      See :meth:`~wx.VListBox.GetSelectionBackground` and :meth:`~wx.VListBox.SetSelectionBackground`

