How to: Create a lookup without Data Source
Good holidays everyone,
This post is dedicated to everyone who already made the question “How the hell do I insert a combo box here?” This happens a lot when you want to use a combo box as a filter.
It should be something simple, maybe it is and I haven’t found yet, but many of us have tried to drag and drop a table to data source and then using the lookup field or using a combo box control.
None of it will work and the only solution I have found so far is to create a lookup without data source.
To illustrate my example I have this form:
As you can see, I would like to use ItemId as a filter but I have no data source.
1. On the form Design, I have created a new StringEdit Control and renamed it to StringEdit_ItemId. See form structure below.
2. Expand the StringEdit_ItemId control and right click on Methods > Override Method > lookup. Like the image below:
3. Now, insert the following code and we are done!
// Override the method lookup()
public void lookup()
{
Query query;
QueryBuildDataSource qbds;
SysTableLookup lookup;
;
// Create the query for the lookup
query = new query();
qbds = query.addDataSource( tableNum(InventTable));
// Instantiate sysTableLookup object using table which will provide the visible fields
lookup = SysTableLookup::newParameters( tableNum(InventTable), this);
// Add fields that will be shown in the lookup as columns
lookup.addLookupfield( fieldNum(InventTable,ItemId));
lookup.addLookupMethod( tableMethodStr(InventTable,itemGroupId));
lookup.addLookupMethod( tableMethodStr(InventTable,defaultProductName));
lookup.addLookupfield( fieldNum(InventTable,NameAlias));
lookup.addLookupfield( fieldNum(InventTable,ItemType));
lookup.addSelectionField( fieldNum(InventTable,Product));
// Add the query to the lookup form
lookup.parmQuery(query);
// Perform the lookup
lookup.performFormLookup();
}
This was originally posted here.

Like
Report


*This post is locked for comments