Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox Value and DisplayText properties 2

Status
Not open for further replies.

rlawrence

Programmer
Sep 14, 2000
182
US
I am struggling with getting a combobox to work the way I want it to. I seem to be missing some basic understanding of how this control works!

When, exactly, is the Value property updated?
And when does the value get displayed?!!!


I'm using the InteractiveChange method to repopulate the list based on the characters the user types in. But in my most recent testing, the Value property never seems to get set--even when I click on the list and select an entry.

As an alternative, I thought I could count on the ListIndex property to let me know when some entry (any entry) had been selected. That doesn't seem to be happening either. But the dropdown list seems correct.

I'm also trying to provide alternate methods for searching and ultimately selecting the entry for this field. But programatically setting the Value property seems to have no effect. The Value is not displayed--even after refreshing.

Setting the ControlSource isn't working for me either. I'd expect the displayed value to change as I navigate through records, but it remains blank!

I guess I'm expecting that the Value property would display and work in conjunction with the ControlSource like it does in a TextBox control. That assumption seems way off.

Can anyone shed any new light on this situation?[neutral]

Thanks,

Ron
 
Your confusion is between the Value property and the DisplayValue property. From what I can see you are talking about the DisplayValue here. Value is effected by the BoundTo property, and based on your setting of this the Value can either be the ListIndex or the ControlSource if numeric.

boyd.gif

 

Ron,

I'm using the InteractiveChange method to repopulate the list based on the characters the user types in.

So, the user types AB, and the list shows all entries beginning with AB. He adds a C, and the list is further filtered to show only those starting with ABC. Is that what you want to achieve?

If so, and if you have you got VFP 9.0, use a textbox instead. The new AutoComplete property gives you exactly the behaviour you are describing.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
When, exactly, is the Value property updated?
And when does the value get displayed?!!!

What is the difference between DisplayValue and Value?

Combo boxes are particularly powerful controls because they enable you to display descriptive text from a lookup table while binding the control to its associated key value. This is possible only because the combo box has these two properties. Understanding the role each of them plays can be confusing, to say the least.

DisplayValue is the descriptive text that is displayed in the textbox portion of the control. This is what you see when the combo box is "closed." The combo's DisplayValue always comes from the first column of its RowSource. On the other hand, the combo's Value comes from whichever column is specified as its BoundColumn. If the BoundColumn of the combo box is column one, its Value and DisplayValue are the same when the user picks an item from the list. When the control's BoundColumn is not column one, these two properties are not the same.


Marcia G. Akins
 
Thank you all for your helpful suggestions. It turns out that there is a link between the RowSource property and the ControlSource that I still don't quite understand.

This combobox is a control that I expect to use on a form to collect names and addresses. If I set the RowSource to [Last_Name, First_Name] from a cursor, and the RowSourceType property to 6, and I set the controlsource to the last_name field in a table, then existing values are displayed as I navigate through records in the table.

However, my table will typically have 40,000 names in it.
In an effort to minimize the selection, I had coded the control to set RowSource="" and RowSourceType=0 until at least 3 characters were typed in. This GREATLY reduces the data selected for list values. But, it also knocks out the control's ability to display existing entries as I navigate through the records of the table!

I'm not really sure why. It doesn't matter to me that there are no drop down values until I have three characters typed in. But it seems to me that the controlsource should remain connected to the displayed value if there is an existing entry in the ControlSource field.

Any suggestions about how to better handle this situation?

Thanks again,

Ron
 
Hi Ron.

I'm not really sure why. It doesn't matter to me that there are no drop down values until I have three characters typed in. But it seems to me that the controlsource should remain connected to the displayed value if there is an existing entry in the ControlSource field.

Unfortunately for you, VFP does not work the way that you think it should ;-) Native combo boxes only display items that are in their internal list. SO if the controlSource can't be found in its RowSource, nothing is displayed in its DisplayValue. You can, however, create a custom subclass that will do this:

Code:
**************************************************
*-- Class:        cbonotinlist 
*-- ParentClass:  combobox
*-- BaseClass:    combobox
*-- Time Stamp:   12/12/99 06:38:09 PM
*-- ALLOWS SELECTION OF AN ITEM NOT IN THE COMBO'S LIST TO BE USED AS ITS CONTROLSOURCE...ONLY WORKS IF THE COMBO'S BOUND COLUMN IS 1
*
DEFINE CLASS cbonotinlist AS cboqfill

  *-- Used to save the control source of the combo before the control is unbound
  ccontrolsource = ""
  Name = "cbonotinlist"

  *-- Called from Valid...it updates the "bound" field
  PROCEDURE updatecontrolsource
  LOCAL lcAlias, lcControlSource
  WITH This
    IF ! EMPTY( .cControlSource )
      lcAlias = JUSTSTEM( .cControlSource )
      IF UPPER( ALLTRIM( lcAlias ) ) = 'THISFORM'
        lcControlSource = .cControlSource
        STORE .DisplayValue TO &lcControlSource 
      ELSE
        REPLACE ( .cControlSource ) WITH .DisplayValue IN ( lcAlias )
      ENDIF
    ENDIF
  ENDWITH
  ENDPROC

  *-- Updates display value from the field in the underlying table if this is a "bound" control
  PROCEDURE refreshdisplayvalue
  LOCAL lcControlSource
  WITH This
    IF ! EMPTY( .cControlSource )
      lcControlSource = .cControlSource
      .DisplayValue = &lcControlSource 
    ENDIF
  ENDWITH
  ENDPROC

  PROCEDURE Init
  IF DODEFAULT()
    WITH This
      .cControlSource = .ControlSource
      .ControlSource = ''
    ENDWITH
  ENDIF
  ENDPROC

  PROCEDURE Valid
  This.UpdateControlSource()
  ENDPROC

  PROCEDURE Refresh
  This.RefreshDisplayValue()
  ENDPROC

  PROCEDURE GotFocus
  IF LOWER( This.Parent.BaseClass ) = 'column'
    *** This is needed so it will work in a grid
    Combobox::GotFocus()
    This.RefreshDisplayValue()
    NODEFAULT
  ELSE
    DODEFAULT()
  ENDIF
  ENDPROC

ENDDEFINE

Marcia G. Akins
 
I've already clicked to thank Marcia, but wanted to publicly state that her solution definitely worked to solve the issue of displaying the controlsource when navigating through records.

Thanks very much for everyone's help.

Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top