Combobox refresh

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

raymanw
Posts: 25
Joined: Tue Mar 08, 2011 1:16 am

Combobox refresh

Post 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.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Combobox refresh

Post 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.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Combobox refresh

Post 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.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
raymanw
Posts: 25
Joined: Tue Mar 08, 2011 1:16 am

Re: Combobox refresh

Post 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.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Combobox refresh

Post 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.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
raymanw
Posts: 25
Joined: Tue Mar 08, 2011 1:16 am

Re: Combobox refresh

Post 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.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Combobox refresh

Post 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
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: Combobox refresh

Post 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
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Combobox refresh

Post 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
Andrés González López
Desde Guadalajara, Jalisco. México.
trmpluym
Posts: 303
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

Re: Combobox refresh

Post 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
Post Reply