Combobox with an array that gets lengthened

Posted on 2009-12-19
Last Modified: 2012-05-08
I've got a combobox with the RowSourceType property set to 5, to use an array.

The last row in the array contains an entry "new". Selecting this allows you to add an extra entry into the list.

Except that once I've added the new entry, I lose the "new" entry at the end of the list.

I think that what's happening is that when I first set up the combobox, VFP works out that it has (say) 200 rows. Adding the extra row means that the array now has 201 rows, with "new" in the 201st row. But VFP still thinks that the array has 200 rows.

I've looked through the object's properties using DEBUG, but the only obvious property is .LISTCOUNT, which is read-only.

Is there another property that I should have incremented in some way?
Question by:IainMacb
    LVL 29

    Expert Comment

    by:Olaf Doschke
    I don't know from the top of my head, but perhaps VFP indeed copies the array you specify to it's own List() array, try adding to it with additem().

    Otherwise a cursor may be the easier rowsource in that case, new records in a cursor will be reflected in the combobox right away.

    Bye, Olaf.
    LVL 41

    Accepted Solution

    AddItem does not help here.

    If you change the RowSource array dimension you have to call Combo's Requery method to update the number of displayed options.

    Following code works in Combo's Valid event (macro substitutions are there just for testing puproses):
      IF .Value = '<New>' AND .RowSourceType = 5
        lcSource = .RowSource
        &lcSource[ALEN(&lcSource)] = 'New opt ' + TIME()
        DIMENSION &lcSource[ALEN(&lcSource)+1]
        &lcSource[ALEN(&lcSource)] = '<New>'
        WAIT WINDOW "Combo selection: " + .Value NOWAIT

    Open in new window

    LVL 1

    Author Comment

    REQUERY() method does the trick. Excellent!


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: (http://msd…
    For Sennheiser, comfort, quality and security are high priority areas. This paper addresses the security of Bluetooth technology and the supplementary security that Sennheiser’s Contact Center and Office (CC&O) headsets provide.  
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now