Results 1 to 6 of 6

Thread: Some VFP custom grid querstions

  1. #1
    Senior Member
    Join Date
    Feb 2012
    Posts
    1,214

    Some VFP custom grid querstions

    Hi,

    A couple of related questions on grids in a custom VFP section.

    1. using addcolumn, how do I specify the header text and rowsource for the column?
    2. How do I specify a custom control for the column?

    Thanks.

    Herb

  2. #2
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    1,948
    Hi Herb,

    It's unclear from the docs whether <grid>.addcolumn() returns on object. If it doesn't, you know which column it is, because you passed the number. In either case, you can set the caption and controlsource properties from there.

    I'm guessing that the ObjectName property holds the reference to the custom control object (a proc that returns a UI object).

    Hank

  3. #3
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,099
    Hi Herb,

    After addcolumn()... you can get objects (column and header)
    See: http://www.lianja.com/community/show...ll=1#post12796

    The Column object (returned from grid.columns(n) has a property called Header1 that returns a reference to the Header object for that column. e.g.

    Code:
    oCol1 = grid1.columns(1)
    oHeader = oCol1.header1
    oHeader.caption = "This is Column 1"
    Josip
    Last edited by josipradnik; 2016-11-15 at 03:26.

  4. #4
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,099
    This is what I tried in VFP custom section:

    Code:
    proc page1_section1
        page1_section1 = createobject("page1_section1")
        page1_section1.addobject("mygrid", "grid")
        mygrid.addcolumn(1)
        oCol1 = mygrid.columns(1)
        oCol1.width=100
        oCol1.addobject("header1","header")
        oHeader = oCol1.header1
        oHeader.caption = "This is Column 1"
    
        mygrid.addcolumn(2)
        oCol2 = mygrid.columns(2)
        oCol2.width=100
        oCol2.addobject("header1","header")
        oHeader2 = oCol2.header1
        oHeader2.caption = "This is Column 2"
    return page1_section1
    This works OK with header captions.
    But when I continued with mygrid.rowsource='categories' and oCol1.controlsource='CATEGORYID' from Southwind, Lianja becomes erratic.

  5. #5
    Senior Member
    Join Date
    Feb 2012
    Posts
    1,214
    Ahhh. Header1.
    I was using header.

    Thanks Josip.

    Now I just need to understand the recordsource for the individual columns. That's giving me a hard time.


    Herb

  6. #6
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,099
    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
    Last edited by josipradnik; 2016-11-16 at 03:24.

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us