<?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=HowToCreateAFormWithAGridAndPopulateItWithData</id>
	<title>HowToCreateAFormWithAGridAndPopulateItWithData - 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=HowToCreateAFormWithAGridAndPopulateItWithData"/>
	<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=HowToCreateAFormWithAGridAndPopulateItWithData&amp;action=history"/>
	<updated>2026-11-21T10:49:58Z</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=HowToCreateAFormWithAGridAndPopulateItWithData&amp;diff=4180&amp;oldid=prev</id>
		<title>Ed: Created page with &quot;First, create a directory to hold the files. I&#039;m calling mine &lt;code&gt;test&lt;/code&gt;.  Next, define the connection to the database by running the &lt;code&gt;CxnEditor.py&lt;/code&gt; script i...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=HowToCreateAFormWithAGridAndPopulateItWithData&amp;diff=4180&amp;oldid=prev"/>
		<updated>2020-05-17T14:24:37Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;First, create a directory to hold the files. I&amp;#039;m calling mine &amp;lt;code&amp;gt;test&amp;lt;/code&amp;gt;.  Next, define the connection to the database by running the &amp;lt;code&amp;gt;CxnEditor.py&amp;lt;/code&amp;gt; script i...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;First, create a directory to hold the files. I&amp;#039;m calling mine &amp;lt;code&amp;gt;test&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next, define the connection to the database by running the &amp;lt;code&amp;gt;CxnEditor.py&amp;lt;/code&amp;gt; script in the Dabo IDE directory. I&amp;#039;m defining a connection to the public &amp;#039;&amp;#039;&amp;#039;MySQL&amp;#039;&amp;#039;&amp;#039; webtest database on the &amp;#039;&amp;#039;&amp;#039;dabodev.com&amp;#039;&amp;#039;&amp;#039; server. Once the connection is working (click the &amp;lt;code&amp;gt;Test...&amp;lt;/code&amp;gt; button to check it!), click the &amp;lt;code&amp;gt;Save&amp;lt;/code&amp;gt; button to save the connection information into your app directory. It creates a small XML file with a &amp;#039;&amp;#039;&amp;#039;.cnxml&amp;#039;&amp;#039;&amp;#039; extension that holds all the information Dabo needs to connect to that database. Make sure to give the connection a meaningful name, since that&amp;#039;s what is used to load it later on; I called mine &amp;#039;&amp;#039;&amp;#039;main&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
OK, now we&amp;#039;re ready to fire up the &amp;#039;&amp;#039;&amp;#039;Class Designer&amp;#039;&amp;#039;&amp;#039;. I&amp;#039;m going to add a grid to the form by right-clicking on the main surface, and selecting &amp;#039;&amp;#039;&amp;#039;Data Controls/ Add Grid&amp;#039;&amp;#039;&amp;#039; from the popup menu, and accepting the default of 3 columns for the grid. I then select the &amp;lt;code&amp;gt;Property Sheet&amp;lt;/code&amp;gt;, which shows that &amp;#039;&amp;#039;&amp;#039;dGrid&amp;#039;&amp;#039;&amp;#039; is the current selection. I want to give the grid a [[RegID]], so that I can more easily refer to it in code, so I enter &amp;lt;code&amp;gt;gridZip&amp;lt;/code&amp;gt; as the value in the [[RegID]] property.&lt;br /&gt;
&lt;br /&gt;
Next I want to customize the &amp;lt;code&amp;gt;Columns&amp;lt;/code&amp;gt;. I can select each by clicking on them in the Designer surface, or by selecting them in the &amp;#039;&amp;#039;&amp;#039;Object Tree&amp;#039;&amp;#039;&amp;#039;, or by pressing &amp;lt;code&amp;gt;Ctrl-PageUp/Down&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;Cmd-PageUp/Down&amp;lt;/code&amp;gt; on OSX) to change the selected object. For each column I want to set the &amp;lt;code&amp;gt;Caption&amp;lt;/code&amp;gt; property to something meaningful, and set the [[DataField]] property to the name of the field in the zipcodes table that will be displayed in that column. So the columns are set so that their &amp;lt;code&amp;gt;Captions&amp;lt;/code&amp;gt; are &amp;#039;&amp;#039;&amp;#039;City&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;State&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;Zip&amp;#039;&amp;#039;&amp;#039;, respectively, while the [[DataField]] properties are set to &amp;#039;&amp;#039;&amp;#039;ccity&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;cstateprov&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;czip&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
If desired, you can set the column widths by dragging the vertical separator lines in the Designer surface, or by manually setting the &amp;lt;code&amp;gt;Width&amp;lt;/code&amp;gt; property in the prop sheet for each.&lt;br /&gt;
&lt;br /&gt;
Now comes the fun part! Select the &amp;#039;&amp;#039;&amp;#039;Code Editor&amp;#039;&amp;#039;&amp;#039; window, and with the &amp;#039;&amp;#039;&amp;#039;Object&amp;#039;&amp;#039;&amp;#039; dropdown set to the form, select &amp;lt;code&amp;gt;afterInitAll&amp;lt;/code&amp;gt; from the &amp;#039;&amp;#039;&amp;#039;Method&amp;#039;&amp;#039;&amp;#039; dropdown.&lt;br /&gt;
&lt;br /&gt;
What we want to do is get the connection, create the bizobj from that connection, configure it to get the data we want, and then populate the grid with that data. Here&amp;#039;s the &amp;lt;code&amp;gt;afterInitAll()&amp;lt;/code&amp;gt; code that is needed to do just that; the comments explain what each bit of code does.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def afterInitAll(self):&lt;br /&gt;
    # The app may automatically load this connection definition,&lt;br /&gt;
    # but just in case it isn&amp;#039;t in the path, we can load it manually. No&lt;br /&gt;
    # connection is made, so there is no harm in adding a connection&lt;br /&gt;
    # definition more than once.&lt;br /&gt;
    self.Application.addConnectFile(&amp;quot;test.cnxml&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    # This call will actually create the connection if it hasn&amp;#039;t already&lt;br /&gt;
    # been made. If it has, it returns the existing connection, so that &lt;br /&gt;
    # multiple connections aren&amp;#039;t used up.&lt;br /&gt;
    conn = self.Application.getConnectionByName(&amp;quot;main&amp;quot;)&lt;br /&gt;
    # Now create the bizobj, using the connection.&lt;br /&gt;
    biz = dabo.biz.dBizobj(conn)&lt;br /&gt;
    # These two properties are essential for every bizobj.&lt;br /&gt;
    biz.DataSource = &amp;quot;zipcodes&amp;quot;&lt;br /&gt;
    biz.KeyField = &amp;quot;iid&amp;quot;&lt;br /&gt;
    # Add it to the form&amp;#039;s collection of bizobj references&lt;br /&gt;
    self.addBizobj(biz)&lt;br /&gt;
&lt;br /&gt;
    # Now set up the fields &lt;br /&gt;
    biz.addField(&amp;quot;iid&amp;quot;)&lt;br /&gt;
    biz.addField(&amp;quot;ccity&amp;quot;)&lt;br /&gt;
    biz.addField(&amp;quot;cstateprov&amp;quot;)&lt;br /&gt;
    biz.addField(&amp;quot;czip&amp;quot;)&lt;br /&gt;
    # Add a WHERE clause to limit the result set&lt;br /&gt;
    biz.addWhere(&amp;quot;ccity = &amp;#039;Springfield&amp;#039; &amp;quot;)&lt;br /&gt;
    # Run the query&lt;br /&gt;
    self.requery()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it! Save the class design into your app directory. You can test it directly from the &amp;#039;&amp;#039;&amp;#039;Class Designer&amp;#039;&amp;#039;&amp;#039; by selecting &amp;lt;code&amp;gt;Run...&amp;lt;/code&amp;gt; from the &amp;#039;&amp;#039;&amp;#039;File&amp;#039;&amp;#039;&amp;#039; menu, or you can select &amp;lt;code&amp;gt;Save Runnable App&amp;lt;/code&amp;gt; to create a &amp;#039;&amp;#039;&amp;#039;.py&amp;#039;&amp;#039;&amp;#039; file you can run directly. Either way, when you run the form, you&amp;#039;ll have a fully-functional grid, populated with the data you specified.&lt;/div&gt;</summary>
		<author><name>Ed</name></author>
	</entry>
</feed>