Hi Herb,
Building grid column by column does not work for me when it comes to databound.
I copy/pasted the end part of example http://www.lianja.com/doc/index.php/..._Visual_FoxPro in my test (blued lines are mine).
Code:
//--------------------------------------------------------------------------
// Subclass a Listbox so that we can define the Click event procedure
define class cls_listbox as ListBox
proc click()
ui_grid.clear
// Note how the AddItems method of Grid, ListBox and Combobox can take
// a SQL SELECT statement as an argument
if trim(this.text) = "All"
ui_grid.additems('select * from example where last_name != " "')
else
ui_grid.additems('select * from example where;
upper(left(last_name,1)) = "' + trim(this.text) + '"')
endif
ui_grid.refresh()
endproc
enddefine
//-------------------------------------------------------------------------------
// Define the main procedure in the section file that will create the section and
// return it to Lianja.
// Note that this must be the same name as the file in which it is contained in.
proc page1_section1
//--------------------------------------------------------------------------
// Make sure the database is open
close database // because I was surprised when the data from another table (of previous testing) was shown in the grid
if database() != "southwind"
open database southwind
endif
//--------------------------------------------------------------------------
// Step 2: Create the Custom Section object
page1_section1 = createobject("page1_section1")
//--------------------------------------------------------------------------
// Step 3: Create a PageFrame class and add it to the Section
page1_section1.addobject("tabs", "pageframe")
//--------------------------------------------------------------------------
// Step 4: Add a Page to the PageFrame class and set some of its properties
tabs.addobject("ui_tab_customers", "page")
ui_tab_customers.caption = "Customers"
ui_tab_customers.show
//--------------------------------------------------------------------------
// Step 5: Add a Container to the Page and set some of its properties
ui_tab_customers.addobject("ui_cont", "container")
ui_cont.autosize = .t.
ui_cont.backcolor = "lightblue"
ui_cont.layout = "horizontal"
ui_cont.margin = 5
ui_cont.spacing = 5
ui_cont.show
//--------------------------------------------------------------------------
// Step 6: Add a subclassed ListBox to the Container and set some of its properties
ui_cont.addobject("ui_listbox", "cls_listbox")
ui_listbox.fixedwidth = 200
//--------------------------------------------------------------------------
// Step 7: Invoke the AddItems method with a comma-separated list of items
// to add to the ListBox
ui_listbox.additems("All,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z")
ui_listbox.show
//--------------------------------------------------------------------------
// Step 8: Add a Grid to the Container
// Note that ui_grid is a namespace variable
ui_cont.addobject("ui_grid", "grid")
ui_grid.show
ui_grid.rowheight = 20
ui_grid.readonly = .t.
ui_grid.recordmark = .f.
ui_grid.closable = .f.
ui_grid.caption = "Sample data"
ui_grid.additems('select * from example where last_name != " "')
col1=ui_grid.columns(1)
head1=col1.header1
head1.caption='AAAAA'
col2=ui_grid.columns(2)
head2=col2.header1
head2.caption='BBBBB'
ui_grid.refresh
ui_grid.autofit
//--------------------------------------------------------------------------
// Step 9: Add a couple more Page classes to the PageFrame
tabs.addobject("ui_tab_orders", "page")
ui_tab_orders.caption = "Orders"
tabs.addobject("ui_tab_shippers", "page")
ui_tab_shippers.caption = "Shippers"
//--------------------------------------------------------------------------
// Step 10: now we must return the Section back to Lianja
return page1_section1
Yes, the headers are changed to AAAAA and BBBBB.
Interesting, when I tried with naming fields instead of *
in ui_grid.additems('select * from example where last_name != " "'),
did not work: I needed to remove columns with ui_grid.removecolumn() one by one.
Josip
Bookmarks