TDBCombo
Source: source/classes/dbcombo.prg
Inherits from: TComboBox
TDBCombo is a database-aware ComboBox that displays values from a DBF field and can return a different value to the bound variable. It supports an incremental search as the user types, and can auto-populate its items from the database when no explicit array is provided.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
cAlias | Character | Workarea alias for the database table (default: current alias) |
cFldList | Character | Field name whose values are displayed in the combo |
cFldItem | Character | Field name whose value is returned to the bound variable |
aList | Array | Array of display strings shown in the dropdown |
aItems | Array | Array of return values corresponding to aList entries |
cSearchKey | Character | Incremental search buffer for keyboard navigation |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, bSetGet, aItems, nW, nH, oWnd, nHelpId, bChange, bValid, nClrFore, nClrBack, lPixel, oFont, cMsg, lUpdate, bWhen, lDesign, acBitmaps, bDrawItem, cAlias, cFldItem, cFldList, aList, nHGet ) | Create a new DBF-aware ComboBox |
ReDefine( nId, bSetGet, aItems, oWnd, ... ) | Redefine from a dialog resource |
Fill() | Populate aItems and aList from the database (called automatically on New/ReDefine if no explicit arrays given) |
Refill() | Re-read the database and repopulate the combo items |
SetItems( aItems, aList, lChanged ) | Set display and return value arrays manually |
Add( cItem, nAt, cList ) | Add an item to the combo at position nAt |
Del( nAt ) | Delete item at position nAt |
ListGet() | Return the selected element of ::aList |
KeyChar( nKey, nFlags ) | Incremental search keyboard handler |
Update() | Refresh the display from the current bound variable |
Example: Combo Linked to Customer City Field
#include "FiveWin.ch"
function Main()
local oWnd, oCombo, cCity := Space( 20 )
use Customer shared new
index on field->city to tmpCity
DEFINE WINDOW oWnd TITLE "TDBCombo Demo" SIZE 400, 150
@ 30, 30 DBCOMBO oCombo VAR cCity ;
ITEMS FIELD->city ;
OF oWnd ;
SIZE 150, 120
ACTIVATE WINDOW oWnd CENTERED
use
return nil
Notes
- TDBCombo can display one field value while returning a different one. For example, show department names (
cFldList) but return department IDs (cFldItem). - Incremental search is supported: typing characters filters the list. Pressing Space resets the search buffer.
- When neither
aItemsnoraListis provided, the constructor callsFill()to auto-populate from the database fields. - The combo data can be manually refreshed with
Refill()when the underlying database records change.