Database Programming Techniques > Selecting and Highlighting Records |
For TDBCombo controls and TDBList controls with MultiSelect set to 0 - None, the SelectedItem property is used to select and highlight an individual record.
For TDBList controls with MultiSelect set to either 1 – Simple, 2 – Extended or 3 – Checkbox, you can select and highlight one or more records at run time by manipulating the list's SelBookmarks collection, which maintains a list of bookmarks corresponding to the selected rows.
Like all other collections in True DBList, the SelBookmarks collection supports Add, Item, and Remove methods and a Count property. For example, to select the list's current row, use the Add method:
Example Title |
Copy Code
|
---|---|
TDBList1.SelBookmarks.Add TDBList1.Bookmark |
After the Add method executes, the collection's Count property is incremented. You can use the Add method repeatedly to select and highlight additional rows
To deselect a single record, use the Remove method, which takes a collection index, not a bookmark:
Example Title |
Copy Code
|
---|---|
TDBList1.SelBookmarks.Remove 0 |
After the Remove method executes, the collection's Count property is decremented. If more than one record is selected, the previous example will only remove the first selected record; that is, the one that was added to the collection first, regardless of its position on the screen. To deselect all records, you need to write a loop like the following:
Example Title |
Copy Code
|
---|---|
With TDBList1.SelBookmarks While .Count > 0 .Remove 0 Wend End With |
Tutorial 6 demonstrates how to use the SelBookmarks collection to select records that satisfy specific criteria.