<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=HowToPopulateAndUseListControls</id>
	<title>HowToPopulateAndUseListControls - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=HowToPopulateAndUseListControls"/>
	<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=HowToPopulateAndUseListControls&amp;action=history"/>
	<updated>2026-11-21T05:10:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://wiki.dabo.leafe.com/index.php?title=HowToPopulateAndUseListControls&amp;diff=4178&amp;oldid=prev</id>
		<title>Ed: Created page with &quot;A common need in an application is to create a list of choices for the user, who makes a selection. The items in the list correspond to a lookup table, and what is stored in t...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=HowToPopulateAndUseListControls&amp;diff=4178&amp;oldid=prev"/>
		<updated>2020-05-17T14:15:35Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;A common need in an application is to create a list of choices for the user, who makes a selection. The items in the list correspond to a lookup table, and what is stored in t...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;A common need in an application is to create a list of choices for the user, who makes a selection. The items in the list correspond to a lookup table, and what is stored in the current table&amp;#039;s record is a foreign key (FK) that points to the entry in the lookup table.&lt;br /&gt;
&lt;br /&gt;
There are three controls that can be used to display a list of choices like this: ([[dListBox]], [[dDropdownList]], and [[dComboBox]]). They all share the same properties to control list selection behavior, so no matter which one you use in your app, the steps are the same.&lt;br /&gt;
&lt;br /&gt;
First, create a method in your bizobj to get the available choices and their corresponding key values. Exactly how you get them depends on your database design, but something like this should get you started:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# This is in your bizobj class&lt;br /&gt;
def getAvailableTypes(self):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Return a 2-tuple of lists of the types and their keys.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    crs = self.getTempCursor()&lt;br /&gt;
    crs.execute(&amp;quot;select pk, typename from mytable order by typename&amp;quot;)&lt;br /&gt;
    ds = crs.getDataSet()&lt;br /&gt;
    # Create the lists&lt;br /&gt;
    names = [rec[&amp;quot;typename&amp;quot;] for rec in ds]&lt;br /&gt;
    keys = [rec[&amp;quot;pk&amp;quot;] for rec in ds]&lt;br /&gt;
    return (names, keys)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then create your list with the following properties:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;DataSource&amp;#039;&amp;#039;&amp;#039; = &amp;lt;bizobj&amp;#039;s [[DataSource]]&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;DataField&amp;#039;&amp;#039;&amp;#039; = &amp;lt;name of the FK field in your table&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;ValueMode&amp;#039;&amp;#039;&amp;#039; = &amp;quot;&amp;lt;code&amp;gt;Key&amp;lt;/code&amp;gt;&amp;quot;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Choices&amp;#039;&amp;#039;&amp;#039; = &amp;lt;list of values (without keys) that should appear in the list&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Keys&amp;#039;&amp;#039;&amp;#039; = &amp;lt;list of keys for the &amp;lt;code&amp;gt;Choices&amp;lt;/code&amp;gt; values&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the lists for &amp;lt;code&amp;gt;Choices&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Keys&amp;lt;/code&amp;gt; should be in the same order, so that the first element of &amp;lt;code&amp;gt;Keys&amp;lt;/code&amp;gt; is the key for the first element of &amp;lt;code&amp;gt;Choices&amp;lt;/code&amp;gt;, and the second element of &amp;lt;code&amp;gt;Keys&amp;lt;/code&amp;gt;... etc.&lt;br /&gt;
&lt;br /&gt;
Now when you navigate to a record, the FK value in the [[DataField]] of that record will cause the list control to show the corresponding name. If the user selects a different item from the list, the FK will be updated with the new choice&amp;#039;s key.&lt;br /&gt;
&lt;br /&gt;
(Newbie [[AppWizard]] users: see http://leafe.com/archives/msg/342481 to access your bizObj from the ui)&lt;/div&gt;</summary>
		<author><name>Ed</name></author>
	</entry>
</feed>