Listbox
From REALbasicWiki
| |||||
|---|---|---|---|---|---|
| Available on | | ||||
| General | |||||
| Superclass | RectControl | ||||
| Interfaces | |||||
| Constants | |||||
| |||||
| Methods | |||||
| Properties | |||||
| Events | |||||
| |||||
|
NOTE: You can get descriptions of the items above from the REALbasic documentation. | |||||
The Listbox control is used to display data in lists and grids.
Contents |
[edit] CellCheck(row as Integer, column as Integer) as Boolean
When a checkbox is displayed in a cell, CellCheck allows you to get or set the checkbox value for the passed row and column.
[edit] Events
As of REALbasic 2008r1, the language reference entry for CompareRows omits the ByRef keyword for the result parameter.
[edit] Gotchas
[edit] CellBackgroundPaint is called for all visible cells.
In order to allow custom drawing of Listbox backgrounds, the CellBackgroundPaint event handler is called for all visible cells, even those that may not correspond to a Listbox row. Thus your code should not assume that the row parameter is the range 0 <= row < ListCount.
[edit] You can't use the CellTextPaint method to draw text or graphics in an empty cell
If you try to draw the contents of a cell yourself (e.g. to use multi-coloured text, fancy arrows or special glyphs) then the CellBackgroundPaint method is problematic as highlighting behaves differently between platforms. However you can use CellTextPaint if you keep the following in mind:
To force a redraw of a cell the InvalidateCell method is used - which in turn calls the CellBackgroundPaint and CellTextPaint methods according to the language reference. However while InvalidateCell calls CellBackgroundPaint on any cell specified it only calls CellTextPaint on cells which contain some text (even if it is only the empty string "").
A Listbox though only initiates the first column, so if you have a listbox with 4 columns and a row is added
Listbox.addrow "abc"
then the last 3 columns contain nothing. Consequently if you try to draw something in them using code in CellTextPaint then it does not get drawn.
The easiest workaround is to just add an empty string to the cells though this might slow down the listbox.
The problem arises from the fact that what is drawn in a cell is not limited to the text entered into the cell, e.g. if the cell contains the text "abc" and CellTextPaint specifies drawstring "this is some fancy text" then both will be drawn. This gives some powerful control to the developer but can be the cause of confusion.
[edit] Using Listboxes
[edit] Sorting
[edit] Clear the Sorted state of a Listbox
If the user has clicked onto a listbox header to sort the column, it is a little bit tricky to remove that "sorted" state from the header again.
Here's how to "unsort" a listbox header again so that its headers appear not in a sorted state:
lb.SortedColumn = -1 // this clears the sorting internally
lb.HasHeading = false // these two lines redraw the listbox header
lb.HasHeading = true
[edit] Tri-state sorting, unsorting
Tri-state sorting happens when the user can switch between sorted and unsorted states.
Here's how to implement such a tri-state sorting in a Listbox:
Add this property to the Listbox or Window (make sure its value is initialized to -1):
mLastSortedColumn as Integer = -1
Add this code to the ListBox.SortColumn event:
if mLastSortedColumn = column and me.ColumnSortDirection(column) = ListBox.SortAscending then
me.SortedColumn = -1
me.HasHeading = false
me.HasHeading = true
rebuildList()
end
mLastSortedColumn = me.SortedColumn
return mLastSortedColumn < 0
Finally, implement a method rebuildList which recreates the unsorted listbox contents
[edit] Adding Items
[edit] Speed optimization
If you're loading thousands of items into a listbox it can take quite a while to fill it. To speed up the process, it might help to make the ListBox invisible while filling it by setting its Visible value to false (whether this helps or not also depends on the REALbasic version you are using).
