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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BLANK COMBOBOX WHEN VALUE NOT IN LIST

Status
Not open for further replies.

craigsboyd

IS-IT--Management
Nov 9, 2002
2,839
US
It appears that unless a combobox has an array as it's rowsource and the style set to 2-Drop Down List that it will not display a value that it does not have a corelating item for. I find this behavior a little odd and would appreciate any comments on it. Perhaps I am missing something here. Please run the code below.


Code:
PUBLIC oForm
oForm = CREATEOBJECT("clsCombo")
oform.show()

DEFINE CLASS clscombo AS form


	Top = 0
	Left = 0
	Height = 277
	Width = 480
	DoCreate = .T.
	Caption = "COMBOBOX TEST"
	Name = "clscombo"


	ADD OBJECT combo1 AS combobox WITH ;
		RowSourceType = 2, ;
		RowSource = "crsFirst", ;
		ControlSource = "cNonexistantColor", ;
		Height = 24, ;
		Left = 24, ;
		Top = 60, ;
		Width = 132, ;
		Name = "Combo1"


	ADD OBJECT combo2 AS combobox WITH ;
		RowSourceType = 2, ;
		RowSource = "crsSecond", ;
		ControlSource = "cNonexistantColor", ;
		Height = 24, ;
		Left = 259, ;
		Style = 2, ;
		Top = 60, ;
		Width = 132, ;
		Name = "Combo2"


	ADD OBJECT combo3 AS combobox WITH ;
		RowSourceType = 5, ;
		RowSource = "aryFirst", ;
		ControlSource = "cNonexistantColor", ;
		Height = 24, ;
		Left = 24, ;
		Top = 153, ;
		Width = 132, ;
		Name = "Combo3"


	ADD OBJECT label1 AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "runs off a cursor drop-down combo", ;
		Height = 17, ;
		Left = 24, ;
		Top = 96, ;
		Width = 194, ;
		Name = "Label1"


	ADD OBJECT combo4 AS combobox WITH ;
		RowSourceType = 5, ;
		RowSource = "arySecond", ;
		ControlSource = "cNonexistantColor", ;
		Height = 24, ;
		Left = 259, ;
		Style = 2, ;
		Top = 153, ;
		Width = 132, ;
		Name = "Combo4"


	ADD OBJECT label3 AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "runs off an array, drop-down combo", ;
		Height = 17, ;
		Left = 24, ;
		Top = 189, ;
		Width = 196, ;
		Name = "Label3"


	ADD OBJECT label4 AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "runs off an array, drop-down combo", ;
		Height = 17, ;
		Left = 259, ;
		Top = 189, ;
		Width = 196, ;
		Name = "Label4"


	ADD OBJECT label2 AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "runs off a cursor drop-list combo", ;
		Height = 17, ;
		Left = 259, ;
		Top = 96, ;
		Width = 180, ;
		Name = "Label2"


	ADD OBJECT label5 AS label WITH ;
		WordWrap = .T., ;
		BackStyle = 0, ;
		Caption = "This is the only one that works the way I expect it to!", ;
		Height = 33, ;
		Left = 259, ;
		Top = 208, ;
		Width = 204, ;
		ForeColor = RGB(128,0,0), ;
		Name = "Label5"


	ADD OBJECT label6 AS label WITH ;
		AutoSize = .T., ;
		FontSize = 14, ;
		BackStyle = 0, ;
		Caption = "#1", ;
		Height = 25, ;
		Left = 24, ;
		Top = 36, ;
		Width = 24, ;
		Name = "Label6"


	ADD OBJECT label7 AS label WITH ;
		AutoSize = .T., ;
		FontSize = 14, ;
		BackStyle = 0, ;
		Caption = "#2", ;
		Height = 25, ;
		Left = 259, ;
		Top = 36, ;
		Width = 24, ;
		Name = "Label7"


	ADD OBJECT label8 AS label WITH ;
		AutoSize = .T., ;
		FontSize = 14, ;
		BackStyle = 0, ;
		Caption = "#3", ;
		Height = 25, ;
		Left = 24, ;
		Top = 128, ;
		Width = 24, ;
		Name = "Label8"


	ADD OBJECT label9 AS label WITH ;
		AutoSize = .T., ;
		FontSize = 14, ;
		BackStyle = 0, ;
		Caption = "#4", ;
		Height = 25, ;
		Left = 259, ;
		Top = 128, ;
		Width = 24, ;
		ForeColor = RGB(128,0,0), ;
		Name = "Label9"


	ADD OBJECT label10 AS label WITH ;
		WordWrap = .T., ;
		BackStyle = 0, ;
		Caption = "The controlsource for all of these comboboxes is the same: cNonExistantColor", ;
		Height = 24, ;
		Left = 24, ;
		Top = 12, ;
		Width = 444, ;
		ForeColor = RGB(128,0,0), ;
		Name = "Label10"


	PROCEDURE Load
		PUBLIC cNonexistantColor
		PUBLIC ARRAY aryFirst(1), arySecond(1)

		cNonexistantColor = PADR("Purple",30," ")

		CREATE CURSOR crsGlobal (Color c(25), PrimaryID I)
		INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("RED", 1)
		INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("GREEN", 2)
		INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("BLUE", 3)
		INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("YELLOW", 4)
		INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("ORANGE", 5)
		INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("WHITE", 6)
		INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("BLACK", 7)
		INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("BROWN", 8)

		SELECT * from crsGlobal INTO CURSOR crsFirst
		SELECT * from crsGlobal INTO CURSOR crsSecond
		SELECT * from crsGlobal INTO ARRAY aryFirst
		SELECT * from crsGlobal INTO ARRAY arySecond
	ENDPROC


ENDDEFINE

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
I would have thought someone else would have run into this. It seems to me that most database applications have some form of lookup lists or user defined fields where data may be in the tables for historical reasons but not necessarily in the lookup list table since the user would only want their current selections to show. Perhaps it is not displaying the same way when others run the above code? For me it shows all the combo boxes blank except for the last one that meets the bizarre criteria needed to show a displayvalue in the combo box that is not a member of its items. Anyone?

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
I'm still curious as to why the control works this way. Anyone?

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
SlightHaze

Wouldn't the ideal situation be that you would allow the user to type a value not found in the source? This would allow the user to add to the source if the value is not found. I've designed many instances where the client requested that the user be allowed to add values. If the combo would work as you suggest I would have been hard-pressed to develop a solution. But has to why it behaves this way I don't know. But knowing the different only adds to the tools available to you.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,

Thank you for the reply. My situation is like this...

Say you have a table called People and in that table is a field called Rating. Now you have another table that is the lookup list for Rating and it holds the values that display when the user drops down the combobox. Let's say you start with the Ratings of: "Excellent", "Good", "Fair", "Poor", and "Very Bad"

and after some months of running the user decides that they no longer want "Very Bad" to show in the drop-down so they remove it from their lookup list table. Now you have a situation where "Very Bad" exists in some of the people records but is not in the lookup list table any longer. So the combo box shows up blank for those people when the user is navigating through the records on their form.

I agree with you that adding values to a lookup list is very important, as important as removing them at some point probably more so. However, it is my experience that there are occurences when a value (such as "Very Bad") is useful and correct for 'historical' data, but not a valid entry for current data/entries being made by the user. It is in some sense 'deactivated' or 'no longer available' however that does not mean that the user necessarily wants to delete it completely from there data or replace it with an empty length string. They want to see it when they are navigating their people but not when they drop down the combo box.

I hope that makes better sense and I haven't succeded in just confusing the issue more.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
SlightHaze

Two suggestions perhaps. If there are records that contain the "Very Bad" comment in the table, and you combo source no longer contains that value:

1.Either do an update on the table and replace all "Very bad" to whatever the client wants to see.
2. Or add the "Very bad" comment to your combo array (or whatever) but show it as disabled (ie. "\" prior to the entry in the rowsource), that way it should show up properly.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
It is possible that the combobox to display other values, but only if ControlSource is empty and Style = 0
Run this code:
Code:
PUBLIC oForm

CREATE CURSOR crsGlobal (Color c(25), PrimaryID I)
INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("RED", 1)
INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("GREEN", 2)
INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("BLUE", 3)
INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("YELLOW", 4)
INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("ORANGE", 5)
INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("WHITE", 6)
INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("BLACK", 7)
INSERT INTO crsGlobal (Color, PrimaryID) VALUES ("BROWN", 8)

oForm = CREATEOBJECT("form1")
oform.show()


DEFINE CLASS form1 AS form


    Top = 16
    Left = 25
    Height = 187
    Width = 495
    DoCreate = .T.
    Caption = "Form1"
    Name = "Form1"


    ADD OBJECT combo1 AS combobox WITH ;
        Comment = "", ;
        Tag = "crsglobal.color", ;
        RowSourceType = 1, ;
        RowSource = "a,b,c,d,e,f,g,h,i,j", ;
        DisplayValue = (crsglobal.color), ;
        ControlSource = "", ;
        Height = 24, ;
        Left = 44, ;
        Style = 0, ;
        Top = 20, ;
        Width = 140, ;
        Name = "Combo1"


    ADD OBJECT list1 AS listbox WITH ;
        RowSourceType = 2, ;
        RowSource = "crsglobal.color", ;
        Height = 157, ;
        Left = 236, ;
        Top = 16, ;
        Width = 201, ;
        Name = "List1"



    PROCEDURE combo1.Init
        this.Refresh
    ENDPROC


    PROCEDURE combo1.Refresh
        IF this.Value <> EVALUATE(this.tag)
            this.ControlSource = ''
            this.DisplayValue = EVALUATE(this.Tag)
        ELSE
            this.ControlSource = this.Tag
        ENDIF
        DODEFAULT()
    ENDPROC


    PROCEDURE list1.InteractiveChange
        thisform.Refresh
    ENDPROC


    PROCEDURE list1.Init
        this.Value = crsglobal.color
    ENDPROC


ENDDEFINE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top