Contents Up Previous Next

wxVListBox

wxVListBox 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 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).

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 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, such as wxHtmlListBox, from it.

However it emits the same events as wxListBox and the same event macros may be used with it.

Derived from

wxVScrolledWindow
wxPanel
wxWindow
wxEvtHandler
wxObject

Include files

<wx/vlbox.h>

See also

wxSimpleHtmlListBox, wxHtmlListBox

Members

wxVListBox::wxVListBox
wxVListBox::Clear
wxVListBox::Create
wxVListBox::DeselectAll
wxVListBox::GetFirstSelected
wxVListBox::GetItemCount
wxVListBox::GetMargins
wxVListBox::GetNextSelected
wxVListBox::GetSelectedCount
wxVListBox::GetSelection
wxVListBox::GetSelectionBackground
wxVListBox::HasMultipleSelection
wxVListBox::IsCurrent
wxVListBox::IsSelected
wxVListBox::OnDrawBackground
wxVListBox::OnDrawItem
wxVListBox::OnDrawSeparator
wxVListBox::OnMeasureItem
wxVListBox::Select
wxVListBox::SelectAll
wxVListBox::SelectRange
wxVListBox::SetItemCount
wxVListBox::SetMargins
wxVListBox::SetSelection
wxVListBox::SetSelectionBackground
wxVListBox::Toggle


wxVListBox::wxVListBox

wxVListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, size_t countItems = 0, long style = 0, const wxString& name = wxVListBoxNameStr)

Normal constructor which calls Create() internally.

wxVListBox()

Default constructor, you must call Create() later.


wxVListBox::Clear

void Clear()

Deletes all items from the control.


wxVListBox::Create

bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxVListBoxNameStr)

Creates the control. To finish creating it you also should call SetItemCount() to let it know about the number of items it contains.

The only special style which may be used with wxVListBox is wxLB_MULTIPLE which indicates that the listbox should support multiple selection.

Returns true on success or false if the control couldn't be created


wxVListBox::DeselectAll

bool DeselectAll()

Deselects all the items in the listbox.

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.

This method is only valid for multi selection listboxes.

See also

SelectAll, Select


wxVListBox::GetFirstSelected

int GetFirstSelected(unsigned long& cookie) const

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

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

Here is a typical example of using these functions:

unsigned long cookie;
int item = hlbox->GetFirstSelected(cookie);
while ( item != wxNOT_FOUND )
{
    ... process item ...
    item = hlbox->GetNextSelected(cookie);
}
This method is only valid for multi selection listboxes.


wxVListBox::GetItemCount

size_t GetItemCount() const

Get the number of items in the control.

See also

SetItemCount()


wxVListBox::GetMargins

wxPoint GetMargins() const

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.

See also

SetMargins


wxVListBox::GetNextSelected

int GetNextSelected(unsigned long& cookie) const

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

This method is only valid for multi selection listboxes.

See also

GetFirstSelected


wxVListBox::GetSelectedCount

size_t GetSelectedCount() const

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.

See also

IsSelected,
GetFirstSelected,
GetNextSelected


wxVListBox::GetSelection

int GetSelection() const

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


wxVListBox::GetSelectionBackground

const wxColour& GetSelectionBackground() const

Returns the background colour used for the selected cells. By default the standard system colour is used.

See also

wxSystemSettings::GetColour,
SetSelectionBackground


wxVListBox::HasMultipleSelection

bool HasMultipleSelection() const

Returns true if the listbox was created with wxLB_MULTIPLE style and so supports multiple selection or false if it is a single selection listbox.


wxVListBox::IsCurrent

bool IsCurrent(size_t item) const

Returns true if this item is the current one, false otherwise.

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


wxVListBox::IsSelected

bool IsSelected(size_t item) const

Returns true if this item is selected, false otherwise.


wxVListBox::OnDrawBackground

void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const

This method is used to draw the items 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.


wxVListBox::OnDrawItem

void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const

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

Parameters

dc

rect

n


wxVListBox::OnDrawSeparator

void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const

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 OnDrawItem().

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

Parameters

dc

rect

n


wxVListBox::OnMeasureItem

wxCoord OnMeasureItem(size_t n) const

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


wxVListBox::Select

bool Select(size_t item, bool select = true)

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

Return true if the items selection status has changed or false otherwise.

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


wxVListBox::SelectAll

bool SelectAll()

Selects all the items in the listbox.

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.

This method is only valid for multi selection listboxes.

See also

DeselectAll, Select


wxVListBox::SelectRange

bool SelectRange(size_t from, size_t to)

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

Return true if the items selection status has changed or false otherwise.

This method is only valid for multi selection listboxes.

See also

SelectAll, Select


wxVListBox::SetItemCount

void SetItemCount(size_t count)

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

This is just a synonym for wxVScrolledWindow::SetLineCount().


wxVListBox::SetMargins

void SetMargins(const wxPoint& pt)

void SetMargins(wxCoord x, wxCoord y)

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.


wxVListBox::SetSelection

void SetSelection(int 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.


wxVListBox::SetSelectionBackground

void SetSelectionBackground(const wxColour& col)

Sets the colour to be used for the selected cells background. The background of the standard cells may be changed by simply calling SetBackgroundColour.

See also

GetSelectionBackground


wxVListBox::Toggle

void Toggle(size_t 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.

See also

Select