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

Values disappear from my combo box 1

Status
Not open for further replies.

mikejcurtis

IS-IT--Management
Mar 24, 2004
17
US
The data is there when I browse table. The Rowsource and RowsourceType are set when the combo has GotFocus by calling the following Method:
LPARAMETERS lall
IF lall
SELECT DIST station as stationa,* from products into cursor temp READWRITE
ELSE
SELECT station as stationa,* from products WHERE ALLTRIM(STR(products.machine))=ALLTRIM(thisform.machine1.combo1.displayvalue) into cursor temp READWRITE
ENDIF
thisform.station1.combo1.rowsource="temp"
thisform.station1.combo1.RowSourceType= 2

The control has the data BoundTo=.T. and the ControlSource is set to datamaster.station

What am I missing?
 
If you change the data source of a list after it has already instantiated, you must call its .Requery()
 
Now I'm noticing that if the content of the ComboBox is a text value, it's displayed. If it's numeric it is recorded in the database, but not displayed in the ComboBox. The data is defined as Character in both tables
 
The content is only displayed when first entered, whether it looks like it's a Character or Numeric value (It's actually only Character in both tables).

If I close the applicationa nd reopen it, the station combo is empty for all rows.

danfreeman: I added the requery to the InteractiveChange, no difference.
 
Mile Lewis, they are both set to the default and the RowSource, 'temp' contains only a single field from the table Products. I thought maybe it was an alignment issue so I set the Alignment to Center, no difference.
 
You are trying to use the combobox as a grid. In the following:

thisform.station1.combo1.rowsource="temp"
thisform.station1.combo1.RowSourceType= 2

Put the temp field that you want displayed in the combobox i.e.
thisform.station1.combo1.rowsource="temp.<fieldname>"
also prior to it:

thisform.station1.combo1.rowsource = ""
i.e. clear the rowsource
make the rowsource "fields"
thisform.station1.combo1.RowSourceType= 6

then do a Requery()
thisform.station1.combo1.requery()

 
Phoo. I did all that Imaginecorp, but it still behaves the same way. I can see the correct value in the table Datamaster.station, but when I bring up the form, the field is blank. If I Edit, then change the value for each row, it sticks as I navigate through the rows, but If I close the form, then re-open it, the field is blank again for all rows.
 
Sorry you are having problems...

First: what is the style of the combobox? If its 0-dropdown combo, change it to 1-dropdown list and lets see if it works.

If not:

Its a Single field that is selected with the Select statement right? and the combobox's controlsource = datamaster.station

Set The parameter Lall outside, make it public (just to test) put the following code in the Dropdown method of the combobox and before clicking the combobox set Lall's value.

Code:
IF empty(lall)
    SELECT DIST station as stationa,* from products into cursor temp 
ELSE
    SELECT station as stationa,* from products WHERE ALLTRIM(STR(products.machine))=ALLTRIM(this.value) into cursor temp 
ENDIF 
with this
.rowsource = ""
.clear
.rowsource = "temp.station"
.rowsourcetype = 6
.requery()
.value = temp.station
endwith


 
sorry should be:
.rowsource = "temp.stationa" not .rowsource = "temp.station"
.value = temp.stationa

 
I tried to incorporate the changes suggested by ImagineCorp, but if I make lall a public variable, then put the code in as suggested above, I get an error about there being no PARAMETER statement.
 
did you remove "LPARAMETERS lall" ? you probably still have it thus the error.
 
Yes I did remove the LPARAMETERS statement. Man I'm really feeling like a pain here. I can't understnad what I'm doing wrong, It would seem this is a very common situation to need, one combo defining the choices for a second one. I'm mystified.
 
It would seem this is a very common situation to need, one combo defining the choices for a second one

What does this mean? I thought it was a simple query from a table. is (thisform.machine1.combo1.displayvalue) another combobox?

OK: Correct me if I am wrong.
1. There are 2 comboboxes.
2. When the second one gets the focus, it creates a query of choices BASED upon the value being displayed in the First combobox.

If the above is true, my previous code will not work. This is how we will have to do it.

1. Make sure the first combobox's Init runs before the second one.
2. The first is displaying a Value. If the control source of the first combobox does not have a value that matches the choices in it, (unless blank) and its a dropdown list, nothing will be displayed.
3. Number 2 applies to the second combobox as well.
"datamaster.station" has to have a value that is either blank or in the choices created, otherwise it will not display.

Maybe, you will have to create a seperate method in the form to create the cursor and set the rowsource. I would not trust Gotfocus()... Let me know how you make out..
 
The following code is to give you an idea on how it can be done. You will have to change the code to your needs...

Code:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


	**************************************************
*-- Form:         form1 (c:\intelisys\combotest.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   02/09/09 10:18:06 PM
*
DEFINE CLASS form1 AS form


	Top = 17
	Left = 63
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT combo1 AS combobox WITH ;
		RowSourceType = 6, ;
		RowSource = "Customers.customerid", ;
		ControlSource = "Customers.customerid", ;
		Height = 24, ;
		Left = 132, ;
		Style = 2, ;
		Top = 38, ;
		Width = 154, ;
		Name = "Combo1"


	ADD OBJECT combo2 AS combobox WITH ;
		Height = 24, ;
		Left = 132, ;
		Style = 2, ;
		Top = 87, ;
		Width = 154, ;
		Name = "Combo2"


	ADD OBJECT label1 AS label WITH ;
		AutoSize = .T., ;
		Caption = "Customer ID:", ;
		Height = 17, ;
		Left = 28, ;
		Top = 42, ;
		Width = 75, ;
		Name = "Label1"


	ADD OBJECT label2 AS label WITH ;
		AutoSize = .T., ;
		Caption = "Orders ID's", ;
		Height = 17, ;
		Left = 37, ;
		Top = 91, ;
		Width = 64, ;
		Name = "Label2"


	PROCEDURE createlist
		If Empty(thisform.combo1.value)
			=Messagebox("Please select a customer id first...",64,"Customer ID")
			Thisform.combo1.SetFocus()
			Return .F.
		Endif
		Select * From orders ;
			WHERE orders.customerid = Thisform.combo1.Value ;
			INTO Cursor temp
		With Thisform.combo2
			.RowSource = ""
			.RowSource = "temp.orderid"
			.RowSourceType = 6
			.Requery()
		Endwith
	ENDPROC


	PROCEDURE Init
		thisform.createlist()
	ENDPROC


	PROCEDURE Load
		If Select("customers") > 0
			Select customers
		Else
			Select 0
			Use Home()+"\samples\northwind\customers.dbf" Shared
		Endif
		Set Order To Tag customerid
		If Select("orders") > 0
			Select orders
		Else
			Select 0
			Use Home()+"\samples\northwind\orders.dbf" Shared
		Endif
	ENDPROC


	PROCEDURE combo2.DropDown
		thisform.createlist()
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************

good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top