ComboBox - edit item

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
dominique_devuyst
Posts: 19
Joined: Wed Dec 20, 2017 8:29 am
DBs Used: DBF
Location: Belgium
Has thanked: 15 times

ComboBox - edit item

Post by dominique_devuyst » Fri Aug 16, 2019 9:13 am

Hello,
I try to edit a combobox item with ON DISPLAYCHANGE .
I start with the Samples\ComBo_4 Demo modified as follow :

Code: Select all

/*
* HMG ComboBox Demo
* (c) 2002 Roberto Lopez
*/
#include "hmg.ch"
Function Main
	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 400 ;
		HEIGHT 200 ;
		TITLE 'ComboBox Demo' ;
		MAIN 
		DEFINE MAIN MENU
			DEFINE POPUP 'Test'
				MENUITEM 'Get Value' ACTION MsgInfo(Str(Form_1.Combo_1.Value))
				MENUITEM 'Set Value' ACTION Form_1.Combo_1.Value := 1
				MENUITEM 'Get DisplayValue' ACTION MsgInfo( Form_1.Combo_1.DisplayValue )
				MENUITEM 'Set DisplayValue' ACTION Form_1.Combo_1.DisplayValue := 'New Text' 
				MENUITEM 'Set Item' ACTION Form_1.Combo_1.Item (3) := 'New Text' 
				MENUITEM 'Get Item' ACTION MsgInfo ( Form_1.Combo_1.Item (3) )
			END POPUP
		END MENU
		@ 10,10 COMBOBOX Combo_1 ;
			ITEMS { 'A' , 'B' , 'C' } ;
			VALUE 1 ;
			DISPLAYEDIT ;
			ON DISPLAYCHANGE Item_edit(This.value)	 //PlayBeep() 
	END WINDOW
	CENTER WINDOW Form_1
	ACTIVATE WINDOW Form_1
Return
***********
function Item_edit
***********
parameter x
Form_1.Combo_1.Item(x):=Form_1.Combo_1.DisplayValue
return
and I have this strange result (see attachment) :
He add a new item each time I press a key.
Does somebody have an explanation to this?
Attachments
ComboBox_demo_edit.png
ComboBox_demo_edit.png (6.82 KiB) Viewed 331 times

User avatar
gfilatov
Posts: 656
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 24 times
Been thanked: 227 times
Contact:

Post by gfilatov » Fri Aug 16, 2019 9:58 am

dominique_devuyst wrote:
Fri Aug 16, 2019 9:13 am
Hello,
I try to edit a combobox item with ON DISPLAYCHANGE .
...
Does somebody have an explanation to this?
Hello Dominique,

It is an expected behavior because a ComboBox value in the ON DISPLAYCHANGE event is equal zero (it is not connected with an any combo value).

Please try the following updated working sample:

Code: Select all

/*
* HMG ComboBox Demo
* (c) 2002 Roberto Lopez
*/
#include "hmg.ch"
static x := 1
Function Main
	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 400 ;
		HEIGHT 200 ;
		TITLE 'ComboBox Demo' ;
		MAIN 
		DEFINE MAIN MENU
			DEFINE POPUP 'Test'
				MENUITEM 'Get Value' ACTION MsgInfo(Str(Form_1.Combo_1.Value))
				MENUITEM 'Set Value' ACTION Form_1.Combo_1.Value := 1
				MENUITEM 'Get DisplayValue' ACTION MsgInfo( Form_1.Combo_1.DisplayValue )
				MENUITEM 'Set DisplayValue' ACTION Form_1.Combo_1.DisplayValue := 'New Text' 
				MENUITEM 'Set Item' ACTION Form_1.Combo_1.Item (3) := 'New Text' 
				MENUITEM 'Get Item' ACTION MsgInfo ( Form_1.Combo_1.Item (3) )
			END POPUP
		END MENU
		@ 10,10 COMBOBOX Combo_1 ;
			ITEMS { 'A' , 'B' , 'C' } ;
			VALUE x ;
			DISPLAYEDIT ;
			ON CHANGE x := This.Value ;
			ON DISPLAYCHANGE Item_edit()
	END WINDOW
	CENTER WINDOW Form_1
	ACTIVATE WINDOW Form_1
Return
***********
function Item_edit
***********
Form_1.Combo_1.Item(x):=Form_1.Combo_1.DisplayValue
return
8-)
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

dominique_devuyst
Posts: 19
Joined: Wed Dec 20, 2017 8:29 am
DBs Used: DBF
Location: Belgium
Has thanked: 15 times

Post by dominique_devuyst » Fri Aug 16, 2019 12:49 pm

Thanks Grigory,
your sample works fine.

Dominique

Post Reply