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!

Grids and Comboboxes

Status
Not open for further replies.

TechGrrl21

Programmer
Dec 26, 2013
7
US
I have been searching this forum and a number of other places and have not quite come up with an answer to this question. I have a state mandated program that requires a user to enter a value on a combobox. The form is set up with a pageframe that contains a grid with about 26 questions in the first column of the grid with a corresponding combobox or date field. When the user selects a value or enters a value from the combobox, I have no issues. When the user tries to enter a value that is not in the combobox's drop down, the value gets lost prior to running the Valid for the combobox.

I have tried a few things with some promise but no actual success. If I set the Sparse to .T. on the Column that the combobox sits on, I can get the value to the Valid without issue. However, the rest of comboboxes and date fields in the column disappear and are replaced with the second column of my table that populates the first column of the grid with questions. The BoundTo or the combobox has been set to .F. and I have also tried setting it to .T.

The Control Source is currently set to a variable for testing but I had it set to a field in a table. The RowSource for the combobox is a cursor and the RowSourceType is set to Alias. I have recreated the combobox on the top level of the form with the same settings of the grid combobox and I do not have this issue.

Any help would be much appreciated!
 
... the value gets lost prior to running the Valid for the combobox.

This might not be relevant, but the last time I saw that problem, I traced it to an unexpected value in the InputMask of the column. I can't remember the details, but I deleted the InputMask and the problem went away. It's a bit of a long shot, but it might be worth checking.

Also, how are you testing for the value entered by the user? Are you aware you should be looking at the combo's DisplayValue rather than its Value? DisplayValue should show the user-entered value at the time that Valid is run. But it is up to you store it back into the underlying table.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
We just tried a few of the comboboxes without the Input mask and got some varying results. On entering data and tabbing or pressing enter, the Value is still lost. On entering data and using the arrow to navigate past the field, somtimes, the DisplayValue is lost but the Value is retained, but could not recreate this consistently.

We have a code set up in the Valid to look at the DisplayValue to see if it is empty or not. If it is not empty, the value is saved to a variable. We use the variable to validate rather than the DisplayValue. However, neither the Value nor the DispayValue has data in it by the time the Valid runs. We put a Set Step On at the beginning of the ComboBox Valid and can see that both of these properties are empty but the DisplayValue will retain two spaces since the Input Mask is set to 99 or XX, in some cases.

Ultimately, we are trying to allow the user to enter a value that is not in the Drop down list. If the data entered is a valid number, then the Valid will insert that into the cursor for the dropdown and the user will save the data to a table when the form is saved.

I have only been programming VFP for the past year and I'm still quite a novice yet so I really appreciate any insight!
 
TechGrrl21 said:
On entering data and tabbing or pressing enter, the Value is still lost. On entering data and using the arrow to navigate past the field, somtimes, the DisplayValue is lost but the Value is retained, but could not recreate this consistently.

Sorry that first sentence should read: On entering data and tabbing or pressing enter, the Value AND DisplayValue are still lost.
 
Comboboxes in Grids are very tricky, so what I did in one case is have a combobox and the classic textbox in the column and only show the combobox in the current row. I have to see in source code how I used a combination of (perhaps) dynamiccurrentcontrol, beforerowcolchange and afterrowcolchange to achieve this look, but it's pretty nice and also looks cleaner than a column of comboboxes.

What I know from the top of my head is, I have two fields for the data, a text field to display the text and a foreign key id field to store the choice of a list of values in the combobox. I think in beforerowcolchange you can still take both displayvalue and value of the combobox and save that choice into both the text field and the foreign id field. And in afterrowcolchange you can do the inverse and set the combobox value. The grid cursor has some redundant data that way, but it's not the table, which later stores the edited data. I always prefer display cursors instead of binding to the tables, as you can introduce additinal fields just needed temporarily for the UI.

Bye, Olaf.
 
Hi,
Please be aware that lis/combo boxes have some difficulties in handling numeric data

From Hacker's Guide to Visual Foypro

"...

The behavior of lists and combos with numeric data confuses people. The key point is that, even when we think we're seeing numbers in a combo or list, we're actually seeing characters. Combos and lists cannot show numeric data. If you specify a RowSource that's numeric, FoxPro internally converts the data to character before displaying it.


The Value of a list or combo (and, therefore, the ControlSource it's bound to) can be either character or numeric. If the Value is character, it contains the text of the currently highlighted item. If the Value is numeric, by default it contains the index of that item. Before VFP 5, there was no way to get numeric data out of a list or combo. The BoundTo property lets you tell VFP to convert a numeric character string to a number before sticking it into Value or DisplayValue.

..."

hth

MK
 
This reminds me I didn't lookup how I did what I suggested. The question is, if you're interested in that way of doing it a sparse=.t. (a combobox only in the current row) orsparse=.f. (a combobox in each row).

Bye, Olaf.
 
Yes, we looked at using the Sparse property and still had some difficulty getting what we required from the Combobox. We actually had to do things entirely different and use a textbox. Part of our issue was stemming from the class. Since we couldn't change the class for the code, we made an exception for this screen. Still not sure why the class is causing the issue but it's something to work with anyway. Thanks, everyone!
 
Hi,
Please have a look at the code below. Maybe it points into the right direction

Code:
PUBLIC oform1
oForm1=NEWOBJECT("form1")
oForm1.Show
RETURN

DEFINE CLASS ComboBox1 as ComboBox
*!*		Validation procedure - you put what you need
	PROCEDURE Valid()
		IF LEN(ALLTRIM(This.DisplayValue)) < 4
			WAIT WINDOW "No valid entry" TIMEOUT 1
		
		ELSE
			IF ASCAN(ThisForm.laNames, This.DisplayValue) = 0
				DIMENSION ThisForm.laNames[ALEN(ThisForm.laNames) + 1]
				ThisForm.laNames[ALEN(ThisForm.laNames)] = This.DisplayValue
				This.Requery()
			ENDIF 
		ENDIF 
	ENDPROC
	
*!*	your may choose from the list or add a new item	
	PROCEDURE InteractiveChange()
		IF This.ListIndex = 0
			ThisForm.txtNames.Value = This.DisplayValue
					
		ELSE
			ThisForm.txtNames.Value = This.List[This.ListIndex, 1]

		ENDIF 
	ENDPROC 
ENDDEFINE 


DEFINE CLASS form1 AS form
Height = 240
Width = 360
Autocenter = .T.
Borderstyle = 2
DIMENSION laNames[3]

	laNames[1] = "Mark"
	laNames[2] = "Caren"
	laNames[3] = "Jeff"

ADD OBJECT txtNames as TextBox WITH Top = 12, Left = 12, Height = 24, ReadOnly = .T.

ADD OBJECT grdNames as Grid with Top = 48, Left = 12, Height = 186, RowHeight = 24, ColumnCount = 1, ;
		RecordSource = "curNames"
	
	PROCEDURE grdNames.Init()
		WITH ThisForm.grdNames.Column1
			.Width = 240
			.Header1.Caption = "Names"
			.AddObject("cboNames","ComboBox1")
			.CurrentControl = "cboNames"
			.cboNames.RowSourceType = 5
			.cboNames.RowSource = "ThisForm.laNames"
			.cboNames.Enabled = .T.
			.cboNames.Visible = .T.
			.Sparse = .F.
		ENDWITH 
	ENDPROC 
	
	PROCEDURE Load()
		CREATE CURSOR curNames (cName C(20))
		INSERT INTO curNames (cName) VALUES ("Dolly")
	
	ENDPROC 
	
	PROCEDURE Destroy()
		USE
	
	ENDPROC 
ENDDEFINE

hth
MK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top