×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Grid ComboBox not populating from cursor
4

Grid ComboBox not populating from cursor

Grid ComboBox not populating from cursor

(OP)
I have a grid with a combobox I inserted. I cannot get the combobox to drop down and show the data from the cursor I am binding it to. I want the data in the cursor selected by the combobox to replace the grid column controlsource value or display it. I have tried a sql query as the style and changing sparse and other settings. Just cannot seem to figure out why I can't get the combobox to fill from my cursor data. Also note that I set the grid recordsource to "cpti" after I build the cursor. I created a new form with just a grid and added a combobox to column3. I can get the dropdown to work if the grid recordsource is a physical table but not a cursor. Makes no sense.

** cursor used for grid combobox for 'packdate'
Create Cursor cPackDate(PackDate c(8))
Insert Into cPackDate (PackDate) Values(" ")
Insert Into cPackDate (PackDate) Values(Dtoc(Date()))
Insert Into cPackDate (PackDate) Values(Dtoc(Date()+1))

column7
sparse = .F.
controlsource = cpti.packdate
bound=.T.

combo1
Bound = .T.
Style = dropdown list
rowsource = cpackdate.packdate
rowsourcetype = 6 - fields



Regards,

Rob

RE: Grid ComboBox not populating from cursor

(OP)
Using a dbf table not a cursor for the grid works. If I use a cursor the combobox does not dropdown and has no value shown. Really goofy. If anyone has figured this out I would still like to use a cursor with the grid. I don't like using DBF's since I have to worry about physical files. But for now I can complete the project.

Regards,

Rob

RE: Grid ComboBox not populating from cursor

Cursors are dbfs, so that's not a difference explaining anything.

Read about the BoundTo property, it has a meaning most people don't recognize.

Quote:

Specifies whether the Value property of a combo box or list box is determined by the List or the ListIndex properties. Available at design time and run time.
and more important the description of the effects of .F.:

Quote:

The Value property is determined by data type of the variable or field specified in the ControlSource property.
If the variable or field specified in the ControlSource property setting is of character type, the Value property is determined by the List property.
If the variable or field specified in the ControlSource property setting is of numeric type, the Value property uses the index number from the ListIndex property.

In both cases the grid controlsouce determines your combobox value and that determines what item is displayed and so a controlsource with just text values is not getting you where you want to get, you always need grid column to be a key for a value in the combobox item list of the combobox. Such direct singel field lists only work quirky, when at all.

Bye, Olaf.

RE: Grid ComboBox not populating from cursor

2
Hi Rob
Please have a look at the code below

CODE -->

PUBLIC go_Form

go_Form = CREATEOBJECT("frmForm")
go_Form.Show

READ Events
CLEAR ALL

DEFINE CLASS frmForm As Form
	Width = 420
	Height = 360
	MinWidth = 420
	MinHeight = 360
	MaxWidth = 420
	MaxHeight = 360
	AutoCenter = .T.

*!*	Add a grid to the form

	Add Object grdNames as Grid with;
		ColumnCount = -1, RecordSource = "csrNames", Visible = .T., ;
		Top = 36, Left = 18, Width = 390, Height = 270
		
		PROCEDURE grdNames.Init()
				With This
					.Visible = .T.
					.RowHeight = 21
					.Column1.Width = 90
					.Column1.Header1.Caption = "Name"
					.Column2.Width = 36
					.Column2.Header1.Caption = "Ch°"
					.Column3.Width = 36
					.Column3.Header1.Caption = "Pfa"
					.Column3.Text1.InputMask = "999"
					.Column4.Width = 240
					.Column4.Header1.Caption = "Institution"
					.Column4.NewObject("cboInstitution","combobox")
					.Column4.CurrentControl = "cboInstitution"
					.Column4.cboInstitution.RowSourceType = 2
					.Column4.cboInstitution.RowSource = "csrEUI"
					.Column4.cboInstitution.Visible = .T.
					.Column4.Sparse = .F.
				EndWith
		ENDPROC 

*!*	Add exitbutton to the form
  
	ADD OBJECT cmdExit As CommandButton WITH ;
    	Width=60, Height=30, Left=18, Top=318, Caption="Exit"
    	
		PROCEDURE cmdExit.Click()
			CLOSE ALL 
			CLEAR Events
			ThisForm.Release
		
		ENDPROC
	  
*!*	ADD code to form's events

	PROCEDURE Destroy()
		ThisForm.cmdExit.Click()
		
	ENDPROC
    
	PROCEDURE Load()
		Create Cursor csrNames (cName C(10), cRoom C(3), nPFA I, cEUI C(20) )
			
			INSERT INTO csrNames (cName, cRoom, nPFA, cEUI) VALUES ("Maxime", "3", 350, "EIB")
			INSERT INTO csrNames (cName, cRoom, nPFA, cEUI) VALUES ("Geoffrey", "5", 650, "Commission")
			
			
		Create Cursor csrEUI (cEUInstitutions C(20))
			
			INSERT INTO csrEUI (cEUInstitutions) VALUES ("EIB")
			INSERT INTO csrEUI (cEUInstitutions) VALUES ("Commission")
			INSERT INTO csrEUI (cEUInstitutions) VALUES ("Parlament")
			INSERT INTO csrEUI (cEUInstitutions) VALUES ("Court of Justice")
			INSERT INTO csrEUI (cEUInstitutions) VALUES ("Court of Auditors")
			
		LOCATE
		
	ENDPROC
ENDDEFINE 

hth

MK

RE: Grid ComboBox not populating from cursor

Hi Rob,

further to MK's excelent sample find here an other one, by Jun, showing different rowsources for each line.

CODE --> vfp

** by Jun Tangunan
loTest = createobject("Form1")
loTest.show(1)

define class Form1 as form
	autocenter= .t.
	height = 200
	width = 600
	caption = 'ComboBox Test'
	windowtype = 0

	add object grid1 as grid with columncount= 3,;
		top = 0, left = 0, headerheight= 0, width = thisform.width, height = thisform.height-40,;
		recordmark= .f., deletemark= .f., scrollbar = 2

	add object command1 as commandbutton with top = 170, left = 10, caption = 'Browse'

	procedure load
		create cursor Stock (StockCode C( 10), description C( 40))
		insert into Stock values ("PROD1", "Product 1")
		insert into Stock values ("PROD2", "Product 2")
		insert into Stock values ("PROD3", "Product 3")

		create cursor Presentation ( PresentationCode C( 10), description C( 40))
		insert into Presentation values( "OPT1", "Option 1")
		insert into Presentation values( "OPT2", "Option 2")
		insert into Presentation values( "OPT3", "Option 3")
		insert into Presentation values( "OPT4", "Option 4")
		insert into Presentation values( "OPT5", "Option 5")
		insert into Presentation values( "OPT6", "Option 6")

		create cursor StockGrades (id C( 10), StockCode C( 10), PresentationCode C( 10))
		insert into StockGrades values ( sys( 2015), "PROD1", "OPT1")
		insert into StockGrades values ( sys( 2015), "PROD1", "OPT2")
		insert into StockGrades values ( sys( 2015), "PROD2", "OPT3")
		insert into StockGrades values ( sys( 2015), "PROD2", "OPT4")
		insert into StockGrades values ( sys( 2015), "PROD3", "OPT5")
		insert into StockGrades values ( sys( 2015), "PROD3", "OPT6")

		create cursor Orders (StockCode C( 10), PresentationCode C( 10), text C( 40), lFlag L)
		insert into Orders values ( "PROD1", "OPT1", "Options are Option 1, Option 2",.f.)
		insert into Orders values ( "PROD2", "OPT3", "Options are Option 3, Option 4",.f.)
		insert into Orders values ( "PROD3", "OPT5", "Options are Option 5, Option 6",.f.)

	endproc

	procedure init
		with this.grid1 as grid
			.recordsourcetype= 1
			.recordsource= 'Orders '
			with .Column2
				.removeobject('text1')
				.addobject( "combo1", "MyCombo")
				.addobject('text1','mytext')
				.text1.visible = .t.
				.dynamiccurrentcontrol = 'IIF(orders.lFlag,"combo1","text1")'
				.sparse = .f.
				.width = 150
				with .combo1
					.rowsourcetype = 3
					.rowsource = "Select P.Description, SG.PresentationCode from StockGrades SG"+;
						" left outer join Presentation P on SG.PresentationCode = P.PresentationCode "+;
						"where SG.StockCode = Orders.StockCode into cursor csrPresentations"
					.boundcolumn = 2
					.style = 2
					.borderstyle = 0
					.visible = .t.
				endwith
			endwith
			.Column3.width = 300
		endwith
		go top in Orders
	endproc

	procedure command1.click
		select Orders
		browse normal
	endproc

enddefine


define class MyCombo as combobox

	procedure lostfocus()
		thisform.grid1.Column2.currentcontrol = 'text1'
		replace lFlag with .f. in Orders
	endproc

enddefine

define class MyText as textbox

	procedure gotfocus()
		replace lFlag with .t. in Orders
		with thisform.grid1.Column2
			.combo1.requery()
			.combo1.listindex = 1
			.currentcontrol = 'combo1'
		endwith
	endproc
enddefine 

Hope this one and or MK's example will help you to make use of cursor i/o dbf
Regards,

Koen

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close