Data Access Worldwide Knowledge Base

Article ID 2000
Article Title HOWTO: Get the new value of a comboform when a user makes a selection
Article URL http://www.dataaccess.com/kbasepublic/kbprint.asp?ArticleID=2000
KBase Category VDF9
Date Created 04/20/2004
Last Edit Date 05/04/2004


Article Text
QUESTION:
When the user clicks on the dropdown arrow of a comboform a list of values is presented for him to select from. When the user clicks on a value, I would like to get that value. If I use the instruction inside the OnCloseUp event:

   Get Value Of oComboForm1 To sValue

I do get the old/current value. I cannot use the OnChange method because I am already using this for a different behavior.

ANSWER:
MSDN says that when a user selects a value the comboform sends two messages. These are CBN_CLOSEUP and CBN_SELCHANGE. CBN_CLOSEUP is mapped to the Visual DataFlex event OnCloseUp and CBN_SELCHANGE to the event Combo_Item_Change, which in its turn calls OnChange. MSDN also says that the order in which these two messages are sent cannot be predicted and this explains why getting the value of the comboform always returns the old value.

You can get the new value by asking the ComboForm control what the current list item is (WinCombo_Current_Item) and with this item number get the value of the N-th list item. So if we have the following OnCloseUp procedure:

Procedure OnCloseUp
    Integer iItem
    String sValue

    Get WinCombo_Current_Item To iItem
    Get WinCombo_Value iItem To sValue
End_Procedure // OnCloseUp

The string variable sValue will contain the current list value which will be placed in the form part of the comboform.

OF SPECIAL NOTE:
1. OnCloseUp is always called when the list part of the comboform is closed. This can close when you select a value but also when the ESC key is pressed. The above example does not know what you did and the messages just take the current combo list value.

2. The above answer/solution makes use of two undocumented messages. Those are not supported and may change in the future, i.e. we cannot guarantee they will be working the same way in future releases of Visual DataFlex.

3. Whenever possible use the OnChange event to react on a change in selection.


Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu


Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.