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 » Thu Mar 17, 2011 7:43 am

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
Has thanked: 100 times
Been thanked: 182 times

Post by Pablo César » Thu Mar 17, 2011 12:54 pm

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
Has thanked: 100 times
Been thanked: 182 times

Post by Pablo César » Thu Mar 17, 2011 1:06 pm

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

Post by raymanw » Fri Mar 18, 2011 7:33 am

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
Has thanked: 100 times
Been thanked: 182 times

Post by Pablo César » Fri Mar 18, 2011 2:15 pm

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

Post by raymanw » Mon Mar 21, 2011 6:35 am

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
Has thanked: 100 times
Been thanked: 182 times

Post by Pablo César » Thu Sep 22, 2011 1:10 am

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: 301
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Has thanked: 3 times
Been thanked: 10 times
Contact:

Post by jairpinho » Tue Nov 15, 2016 1:12 am

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: 1144
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 35 times
Been thanked: 68 times
Contact:

Post by andyglezl » Tue Nov 15, 2016 1:33 am

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: 242
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands
Has thanked: 6 times
Been thanked: 21 times

Post by trmpluym » Sun Nov 20, 2016 12:15 pm

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