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

Combo Box Selection with cursor pointer 1

Status
Not open for further replies.

taterday

Programmer
Jan 28, 2009
183
US
I have a combo box
rowsource: selection of a table where table1.field1 = table2.field1 and table1.field2 = table2.field2 into a cursor order by field3,field4
row source type: 3 SQL statement
style: 2 drop down list

Field3 and field4 do not exist in table1
I am after the data in table2

I use a locate statement in the right click event in the list box if they want this feature. I requery the combo box and refresh. The data is filter correctly in that I only get Smiths.

There is a link in table1 to table2 that meets my criteria but many records in the table2.

This is my problem
They want the combo box to highlight or be on the record that they highlight in the list box. If it is on field3(Smith) field4(John), they want it to starts on John. It now starts on Andy, who is first in the selecton query.

I have used a locate after the combox requery statement and have found the record in the cursor but can not set the pointer there.

I hope I have explained this well enough.

Thank you.
 
wel this is how you do it with the select in the dropdown of the combobox

Code:
PUBLIC oform1

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


	**************************************************
*-- Form:         form1 (c:\intelisys\combovalue.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   03/16/09 04:06:00 PM
*
DEFINE CLASS form1 AS form


	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT list1 AS listbox WITH ;
		ColumnCount = 2, ;
		ColumnWidths = "65,75", ;
		Height = 163, ;
		Left = 18, ;
		Top = 21, ;
		Width = 134, ;
		Name = "List1"


	ADD OBJECT combo1 AS combobox WITH ;
		BoundColumn = 1, ;
		ColumnCount = 3, ;
		ColumnWidths = "75,75,75", ;
		Value = "", ;
		Height = 24, ;
		Left = 205, ;
		Style = 2, ;
		Top = 64, ;
		Width = 100, ;
		Name = "Combo1"


	PROCEDURE Load
		CREATE CURSOR temp (cname1 c(25), cname2 c(25), cname3 c(25))
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("john","smith","tom")
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("john","jane","tom")
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("tom","andy","smith")
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("john","joe","tom")
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("john","will","tom")
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("john","joel","tom")
	ENDPROC


	PROCEDURE list1.Init
		Select * From temp Into Cursor ccursor
		With This
			.RowSource = "ccursor.cname1,cname2"
			.RowSourceType = 6
			.Requery()
			.Value = .topindex
		Endwith
	ENDPROC


	PROCEDURE combo1.DropDown
		Select * From temp ;
			WHERE ccursor.cname1 = temp.cname1 And  ;
			ccursor.cname2 = temp.cname2 ;
			Into Cursor combocursor
		With This
			.RowSource = ""
			.RowSource = "combocursor.cname1,cname2,cname3"
			.RowSourceType = 6
			.Value = ccursor.cname1
		Endwith
	ENDPROC


	PROCEDURE combo1.Init
		this.DropDown()
	ENDPROC


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

Again this is to give you an idea how it can be done, you will have to fine tune

Strange how the replies vanished...
 
The problem is table 2 has 25,000 plus records. I am query only for ones that meet the list box criteria field1,field2.
I want to zero in on field3 and field4 that selected in the list box.

They may want the person above or the ones below. If I could just get the drop down to reset the pointer and highlight the record. I would be finished with this request.

Thank you,


 
The first code should do that...highlight the record in the combobox...
 
The first code should do that...highlight the record in the combobox...

Do you mind restating this?
 
had to redo this as I did not save the code... for both the listbox and combobox use fields and cursors i.e. rowsourcetype = 6 for this to work...

Code:
PUBLIC oform1

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


	**************************************************
*-- Form:         form1 (c:\intelisys\combovalue.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   03/16/09 04:59:11 PM
*
DEFINE CLASS form1 AS form


	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT list1 AS listbox WITH ;
		ColumnCount = 2, ;
		ColumnWidths = "65,75", ;
		Height = 163, ;
		Left = 18, ;
		Top = 21, ;
		Width = 134, ;
		Name = "List1"


	ADD OBJECT combo1 AS combobox WITH ;
		BoundColumn = 1, ;
		ColumnCount = 3, ;
		ColumnWidths = "75,75,75", ;
		Value = "", ;
		Height = 24, ;
		Left = 205, ;
		Style = 2, ;
		Top = 64, ;
		Width = 100, ;
		Name = "Combo1"


	PROCEDURE Load
		CREATE CURSOR temp (cname1 c(25), cname2 c(25), cname3 c(25))
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("john","smith","tom")
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("john","jane","tom")
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("tom","andy","smith")
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("john","joe","tom")
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("john","will","tom")
		INSERT INTO temp (cname1,cname2,cname3) VALUES ("john","joel","tom")
	ENDPROC


	PROCEDURE list1.DblClick
		Select ccursor
		For x = 1 To Thisform.combo1.ListCount
			If Alltrim(Thisform.combo1.ListItem(x,1)) = Alltrim(ccursor.cname1)   And ;
					ALLTRIM(Thisform.combo1.ListItem(x,2)) = Alltrim(ccursor.cname2)
				Exit
			Endif
		Endfor
		Thisform.combo1.value = x
	ENDPROC


	PROCEDURE list1.Init
		Select * From temp Into Cursor ccursor
		With This
			.RowSource = "ccursor.cname1,cname2"
			.RowSourceType = 6
			.Requery()
			.Value = .topindex
		Endwith
	ENDPROC


	PROCEDURE combo1.Init
		Select * From temp ;
			Into Cursor combocursor
		With This
			.RowSource = ""
			.RowSource = "combocursor.cname1,cname2,cname3"
			.RowSourceType = 6
		Endwith
	ENDPROC


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

 
Thank you. I appreciate your advise. I know you went to alot of trouble for me. I can't use the row source 6. I have used that before and I had to have a filter to control the Smith being the only one displayed. It was slow and error prone. I need to use my select. They noticed the differnce in their response and say it now works correctly.

What they wanted seem so simple. I could locate the record and point to it. When I do the select at the command window. locate the record. I can open the brow window and the pointer is in the record I need. Just looks like I could move to that record in the combo box.

Any other way anyone can think of. I know there has to be a way to do this and keep the SQL statement.




 
so just change the rowsource to the select statement and rowsourcetype to 3, it will still work...though I would not use filters

Dont worry about the time spent... I have always considered it as time well spent learning/refreshing my knowledge

Sorry it did not work out
 
Thank you. I did the locate in the gotfocus and set the value to ... and it's working close enough. I am close to what they want.

Thank you again for hanging in there.

You are eligible for a star.
 
Thank you, glad I could help.

Just curious, why didnt the above code work?
 
It is my lack of knowledge. I didn't understand how to adapt your code to the condition I had. I do better with "put this a statement in ... event."

This feature is not activate unless there is a right click event in the list box. The combo box is controlled by the first field but what I wanted was to go to the combination of the two fields. The locate in the gotfocus puts me in the ballpark. I am going to the first field now. Since that gets me down to approximately 15 records for them to search. I would like to get to the combination level.

Thank you again.

 
For x = 1 To Thisform.combo1.ListCount
If Alltrim(Thisform.combo1.ListItem(x,1)) = Alltrim(ccursor.cname1) And ;
ALLTRIM(Thisform.combo1.ListItem(x,2)) = Alltrim(ccursor.cname2)
Exit
Endif
Endfor
Thisform.combo1.value = x
ENDPROC

I used this in the gotfocus and it works! The users will be pleased for a minute. You know they always want more. Job jusification! Thank you for making me look good.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top