Hi John.
Platform: Win Python Version: 2.4.4 on win32 Dabo Version: Version 0.8a; Revision UI Version: 2.6.3.3 on wxMSW
I don't think I'm being dense. I took a couple days off to clear my head and came back to this. Below is my code and the form .cdxml file, which still don't work as I expect, with comments.
To summarize:
I can make a grid work just like it does in the Wiki How-To for populating a grid. That strongly suggests to me that I'm doing everything right with regard to setting up the database in MySQL, creating a connection in Dabo, and accessing the proper biz object, DataSource, and fields.
So then, insofar as possible, I use the exact same database, table, and Dabo code to bind a textbox to a single field in in my table and populate it by requesting 1 record, and it doesn't work. Instead, the GRID shows the one row I want, and the textbox shows nothing. If I get rid of the grid and just do the textbox thing with everything else the same, it doesn't do anything at all.
As best I can tell, it should work. Please try to show me the exact point where I'm wrong.
Thanks.
Ken Dibble www.stic-cil.org
## *!* ## Dabo Code ID: dButton-dForm def onHit(self, evt): # Code from the wiki How-To: # This connection works fine, as the rest of this code # demonstrates. self.Form.Application.addConnectFile("C:\DaboProjects\MyMusic\mymusic.cnxml")
# Code from the wiki How-To: conn = self.Form.Application.getConnectionByName("main")
# Code from the wiki How-To: biz = dabo.biz.dBizobj(conn)
# Code from the wiki How-To: # These items are correct, as the grid will demonstrate. biz.DataSource = "musSongs" biz.KeyField = "pkid"
# Code from the wiki How-To (don't know why; it doesn't # seem to serve any purpose, like giving me a form-level # reference to the biz object that I can use, but if # I comment it out, the grid doesn't populate): # Add it to the form's collection of bizobj references self.Form.addBizobj(biz)
# Code from the wiki How-To: # These items are correct, as the grid will demonstrate. # Now set up the fields biz.addField("pkid") biz.addField("songname") biz.addField("compdate")
# Code from the wiki How-To: # Run the query biz.requery()
# Code from the wiki How-To (works perfectly; if I # don't enter a number in the keyBox textbox, all of my # songs appear in the grid. This indicates that: # 1. The MySQL database is configured properly for # Dabo. # 2. The connection is configured properly in Dabo. # 3. I'm referring to the proper fields and DataSource. # 4. There is data in the table.) # The grid may not exist yet; it may be created after # this method is run. So use 'callAfter()' to delay # populating the grid until we know it is ready. dabo.ui.callAfter(self.Form.populateGrid)
# Now try to show just one song in the thisSong textbox, # assuming the user entered a number in the keyBox. If # s/he didn't, the following code doesn't do anything # that I can see. myPK = self.Form.keyBox.Value
# Assuming I put 3 in the keyBox,Prints 3, as I'd expect. print myPK
biz.setWhereClause("musSongs.pkid = " + myPK)
# Assuming I put 3 in the keyBox, this prints # "musSongs.pkid = 3", also as I'd suspect. # This tells me that the query is going to be correct. print biz._CurrentCursor.sqlManager._whereClause
biz.requery()
# At this point, the grid shows one row--the row I # wanted--but the thisSong texbox shows nothing. dabo.ui.callAfter(self.Form.showSong)
## *!* ## Dabo Code ID: dForm-top def afterInit(self): # Even though I do this again in the button's onHit, # I do it here because the form will not run if there's # no code in this method. self.Application.addConnectFile("C:\DaboProjects\MyMusic\mymusic.cnxml")
def populateGrid(self): # Just like in the Wiki How-To: self.gridKen.DataSource = "musSongs"
def showSong(self): # Just like in the Wiki How-To except it's a dTextBox # instead of a dGrid. self.Form.thisSong.DataSource = "musSongs"
Here's the .cdxml file for the form:
<?xml version="1.0" encoding="utf-8" standalone="no"?> <dForm code-ID="dForm-top" Caption="Songs" Top="90" Height="547" Width="682" designerClass="DesForm" UseSizers="True" Left="262"> <dSizer SlotCount="4" designerClass="LayoutSizer" Orientation="Vertical"> <dGrid ColumnCount="3" RegID="gridKen" SelectionMode="Cell" designerClass="controlMix" sizerInfo="{'BorderSides': ['All'], 'Proportion': 1, 'HAlign': 'Left', 'VAlign': 'Top', 'Border': 0, 'Expand': True}"> <dColumn HeaderFontItalic="False" FontUnderline="False" Width="150" FontFace="Arial" HeaderBackColor="None" FontBold="False" HeaderVerticalAlignment="None" Editable="False" HeaderFontBold="True" ListEditorChoices="[]" FontItalic="False" Expand="False" HeaderFontSize="9" Sortable="True" HeaderFontFace="Arial" Caption="ID" designerClass="controlMix" Order="0" FontSize="9" HeaderForeColor="None" Searchable="True" HeaderFontUnderline="False" HeaderHorizontalAlignment="None" HorizontalAlignment="Left (Automatic)" DataField="pkid" VerticalAlignment="Top"></dColumn> <dColumn HeaderFontItalic="False" FontUnderline="False" Width="150" FontFace="Arial" HeaderBackColor="None" FontBold="False" HeaderVerticalAlignment="None" Editable="False" HeaderFontBold="True" ListEditorChoices="[]" FontItalic="False" Expand="False" HeaderFontSize="9" Sortable="True" HeaderFontFace="Arial" Caption="Song" designerClass="controlMix" Order="10" FontSize="9" HeaderForeColor="None" Searchable="True" HeaderFontUnderline="False" HeaderHorizontalAlignment="None" HorizontalAlignment="Left (Automatic)" DataField="songname" VerticalAlignment="Top"></dColumn> <dColumn HeaderFontItalic="False" FontUnderline="False" Width="150" FontFace="Arial" HeaderBackColor="None" FontBold="False" HeaderVerticalAlignment="None" Editable="False" HeaderFontBold="True" ListEditorChoices="[]" FontItalic="False" Expand="False" HeaderFontSize="9" Sortable="True" HeaderFontFace="Arial" Caption="Date" designerClass="controlMix" Order="20" FontSize="9" HeaderForeColor="None" Searchable="True" HeaderFontUnderline="False" HeaderHorizontalAlignment="None" HorizontalAlignment="Left (Automatic)" DataField="compdate" VerticalAlignment="Top"></dColumn> </dGrid> <dTextBox RegID="keyBox" sizerInfo="{'BorderSides': ['All'], 'Proportion': 0, 'HAlign': 'Left', 'VAlign': 'Top', 'Border': 3, 'Expand': False}" designerClass="controlMix"></dTextBox> <dButton code-ID="dButton-dForm" Caption="Button" sizerInfo="{'BorderSides': ['All'], 'Proportion': 0, 'HAlign': 'Left', 'VAlign': 'Middle', 'Border': 4, 'Expand': False}" designerClass="controlMix"></dButton> <dTextBox RegID="thisSong" sizerInfo="{'BorderSides': ['All'], 'Proportion': 0, 'HAlign': 'Left', 'VAlign': 'Top', 'Border': 3, 'Expand': False}" designerClass="controlMix" Name="dTextBox1"></dTextBox> </dSizer> </dForm>
-- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.5/706 - Release Date: 2/28/2007 4:09 PM
©2007 Ken Dibble |
|