Page 1 of 2

Combobox refresh

Posted: Thu Mar 17, 2011 7:43 am
by raymanw
Hi all,

How do I refresh a combobox using the current record value?

I created the combobox using the ITEMSOURCE parameter pointing to a combination of 2 table fields. When I try to assign the current record value to its value property, it get the error: "value property wrong type (only numeric allowed)"

Thanks.

Combobox refresh

Posted: Thu Mar 17, 2011 12:54 pm
by Pablo César
I would use ITEMS parameter on COMBOBOX adding, modifying, deleting elements of one array. See example of C:\hmg.3.0.35\SAMPLES\COMBO.5 for more details.

Combobox refresh

Posted: Thu Mar 17, 2011 1:06 pm
by Pablo César
I saw C:\hmg.3.0.35\SAMPLES\COMBO.6 too and possible is very close what you are using... please post part of your code to evaluate it.

Re: Combobox refresh

Posted: Fri Mar 18, 2011 7:33 am
by raymanw
Hi Pablo,

Here is my logic:
1. stktrans->item_type = stkitem->item_type
2. grid defined with ROWSOURCE "StkTrans"
3. combobox defined with ITEMSOURCE StkItem->item_type & VALUESOURCE StkItem->item_type
4. click on a different record in the grid triggering "On Change ChangeUpdate()"
5. ChangeUpdate() do stkitem->dbseek()
6. combobox should display the corrent value.

I tried the example of C:\hmg.3.0.35\SAMPLES\COMBO.6 but it remains blank when I click on a different record in the grid.

Thanks.

Combobox refresh

Posted: Fri Mar 18, 2011 2:15 pm
by Pablo César
2. grid defined with ROWSOURCE "StkTrans"
You have not mentioned this before...

To make a changeable itens of combobox in one Grid, will demands very much code as mentioned Mr. rathinagiri in this post http://hmgforum.com/viewtopic.php?f=14&t=1627 and see "Control Definition Array" of HMG help in Grid definitions.

I have got a result (based in C:\hmg.3.0.35\SAMPLES\GRID.15\demo.prg) with fixed itens of combobox of one grid but not changeable itens. I believe this happen because these values are already encapsullated in Grid properties when started.

IMO I would use ON GOTFOCUS of your grid to call a function with conditional options: when is in focous of that column and that value then SetProperty of new itens of combobox...

I very interested to know how to solve this problem, but my knowledges are still very poor in HMG, sorry.

Re: Combobox refresh

Posted: Mon Mar 21, 2011 6:35 am
by raymanw
Hi Pablo,

I opted to use the array method as in this case the values don't change within the session of the form.

Thanks.

Combobox refresh

Posted: Thu Sep 22, 2011 1:10 am
by Pablo César
Recentely, I found a way to reproduce a non existent function of "refresh" within combobox. In my function when I change itens of combobox (arrays itens), I make following:

- Reconstruct array elements with new values
- Then use DeleteAllItems, making like this for example: Win_1.Combo_2.DeleteAllItems
- After this, you can use AddItem() function to reconstruct with new itens. And I do like this:
For i=1 to Len(aLinha)
Win_1.Combo_2.AddItem(aLinha)
Next
- Then you need to be retablished the first item of Comobobox and you can use like this: SetProperty("Win_1","Combo_2","Value",1)

I hope this my experience to be usefull for someone alse in future. Best regards

Re: Combobox refresh

Posted: Tue Nov 15, 2016 1:12 am
by jairpinho
I can not update the items of the combobox through an arrays follow the code

DEFINE COMBOBOX Combo_1
ROW 130
COL 370
WIDTH 240
HEIGHT 100
ITEMS aProdutos
VALUE 1
FONTNAME "Arial"
FONTSIZE 9
TOOLTIP ""
ONCHANGE
ONGOTFOCUS Nil
ONLOSTFOCUS Nil
FONTBOLD .F.
FONTITALIC .F.
FONTUNDERLINE .F.
FONTSTRIKEOUT .F.
HELPID Nil
TABSTOP .T.
VISIBLE .T.
SORT .F.
ONENTER Nil
ONDISPLAYCHANGE Nil
DISPLAYEDIT .F.
IMAGE Nil
DROPPEDWIDTH Nil
ONDROPDOWN Nil
ONCLOSEUP Nil
END COMBOBOX


Function Pesquisa_Produtos(nTipo)
*********************************************************************************************************************************************************************
Local cCodigo_Cliente := PGeneric( 2 , "codigo" , "clientes" , "nome" , ' "'+ Alltrim(Form_Novo_Pedido.Cb_Clientes.DisplayValue) +'" ' )

aProdutos := EncheArray_Generic( 2 ,"produtos", .F. , 2 , "cliente" , cCodigo_Cliente)

Form_Novo_Pedido.Combo_1.Value := 1

return

Re: Combobox refresh

Posted: Tue Nov 15, 2016 1:33 am
by andyglezl
aProdutos := EncheArray_Generic( 2 ,"produtos", .F. , 2 , "cliente" , cCodigo_Cliente)

Form_Novo_Pedido.Combo_1.DeleteAllItems
FOR i1 = 1 TO LEN( aProdutos )
Form_Novo_Pedido.Combo_1.AddItem( aProdutos[ i1 ] )
NEXT

Re: Combobox refresh

Posted: Sun Nov 20, 2016 12:15 pm
by trmpluym
I created a small universal function for the refresh of a ComboBox with a one dimensional array source.

It is simple but maybe it can help some others :)

Code: Select all

FUNCTION RefreshCombobox(cWindowName,cComboBoxName,aArrayName)

LOCAL nX

DoMethod(cWindowName,cComboBoxName,'DeleteAllItems') 

FOR nX = 1 TO LEN(aArrayName)
   DoMethod(cWindowName,cComboBoxName,'AddItem',aArrayName[nX]) 
NEXT

aSort(aArrayName)

Return