Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox not populated with array 1

SitesMasstec

Programmer
Sep 26, 2010
569
Brasil
Hello colleagues!

I am trying to put in a Combobox the data from an array.

These are the data from the array I am using (just to be sure that the array has these data; the similar code is in the procedure Init in the Form):

VFPArray.jpg

This is the Form:

VFPComboboxArray.jpg
As you can see, the data from the array are not presented in the Combobox.

This is the code in the procedure AddItem in the Combobox:

Code:
With This
    FOR I=1 TO 3  && QtdeNomes
       .AddItem(NOMES(I,1),NOMES(I,2))
    NEXT I
    .ListIndex=1
ENDWITH

Thank you.
 
Your parameters to the method AddItem are incorrect. The first parameter is the text to display, the second parameter is the index value (numeric), and the third parameter is the column value (numeric). So, the correct code should be (untested):

Code:
With This
    FOR I=1 TO 3  && QtdeNomes
       .AddItem(NOMES(I,1), I, 1)
       .AddItem(NOMES(I,2), I, 2)
    NEXT I
    .ListIndex=1
ENDWITH

Also, see the property ColumnWidths. If you do not want the second column to be displayed in the dropdown selections, then set this property to the width of the control followed by zero. For example, if the control width is 100, then the property value would be ColumnWidths=200,0.

If you want the second array column to be the index value (numeric), then to use AddListItem where you specify the ListItemId. Note that ListIndex returns the sequential value; 1, 2, 3, ... and you should determine the selected value from ListItemId property.

I use the following code to populate comboboxes:

Code:
LOCAL lnCnt
SELECT id, bname FROM banks WHERE companyid = _VFP.CompanyId AND active = True AND !EMPTY(assetgrpid) INTO CURSOR c_temp
lnCnt = 0
SELECT c_temp
SCAN
    lnCnt = lnCnt + 1
    this.AddListRow(lnCnt, ALLTRIM(c_temp.bname), c_temp.id)
ENDSCAN
IF this.ListCount > 0
    this.ListItemId = 1
ENDIF
USE IN SELECT('c_temp')

The method "AddListRow" is a custom method that I added to my sub-class of the combobox:

Code:
PROCEDURE AddListRow
LPARAMETERS tnItemID, tcItem1, tcItem2, tcItem3, tcItem4, tcItem5, tcItem6, tcItem7, tcItem8, tcItem9, tcItem10, tcItem11, tcItem12
LOCAL lnCnt, lcParm
FOR lnCnt=1 TO PCOUNT()-1
    lcParm = "tcItem" + TRANSFORM(lnCnt)
    this.AddListItem(EVALUATE(lcParm), tnItemID, lnCnt)
ENDFOR
ENDPROC
 
Last edited:
Hello, Greg!

I uderstand your method works .

But as I have an array in memory, why not just my code in the AddItem in the Combobox doesn't work?
 
Try this code:

Code:
With This
    FOR I=1 TO 3  && QtdeNomes
       .AddListItem(NOMES(I,1), NOMES(I,2))
    NEXT I
    .ListIndex=1
ENDWITH

This sets the ListItemId value and not the ListIndex. To know which item was selected:

Code:
 lnSelectedItemId = this.ListItemId
 
Just a thought.

I didn't read the whole thread, but if the control is completely empty, perhaps you also need to add a REFRESH().

Even with the wrong parameters for the array elements, it wouldn't be empty. You'd see numbers or even a bunch of blank lines.
 
Hello, Joe!
It doesn't work, either.
Please see the code in the Init procedure in the Form:

Code:
    DECLARE NOMES(1,1)
   
    NOMES(1,1)="-"

    thisform.txtNOME.Value=YNOMECLI
    NOMECLI=YNOMECLI

    IF NOMECLI<>SPACE(34)
        NOMECLI=UPPER(ALLTRIM(NOMECLI))
        SELECT NOMAGENTE+"  (" + ALLTRIM(STR(CODAGENTE)) + ")  " + "Localizador: " + LOCALIZA, RECNO();
            FROM RESERVAS;
            WHERE UPPER(NOMAGENTE) LIKE "%&NOMECLI%" INTO ARRAY NOMES


        IF NOMES(1,1)="-"              
            RETURN               
      
       ELSE                          
            =ASORT(NOMES)
            QtdeNomes=ALEN(NOMES)
           
            thisform.cboNOMES.Refresh()
           
         ENDIF
    ENDIF

RETURN
 
I was referring to adding the REFRESH() directly after the code you use to add the items to the control.
 

Part and Inventory Search

Sponsor

Back
Top