Ahsan Amin


I have to locate the CourseID field from a table. I have a combo box that list the CourseName field.

CourseID CourseName

------------- -------------------

1 SE

2 VFP

3 ASP

Now if use select VFP from the Combo i want the courseid 2. I am using the follwoing code

LOCATE FOR a_Courses.CourseName = thisform.cboCourse.value

MESSAGEBOX(a_Courses.CourseID)




Re: Locate Command

Markish


Hi Amin,

If you have given the following

Code Snippet

thisform.cboCourse.recordsource = "a_courses.CourseName"

thisform.cboCourse.recordsourcetype=6 && Fields

Then When selcting the combo the record pointer also moves in the a_courses table. Hence you can use

Code Snippet
Messagebox(a_courses.courseid)

Best regards,
Markish







Re: Locate Command

CetinBasoz

I think this question is related with your other question. When there is ID it's not wise to loacte by name to get ID and you really don't need it. Get t directly from combo's source cursor. ie:

Public oForm

oForm = Createobject('MyForm')

oForm.Show

Define Class myForm As Form

DataSession = 2

Add Object cboCourse As ComboBox With ;

left=10, Top=10

Add Object cmdShowSelected As CommandButton With ;

left = 10, Top = 60, Caption="Show Selected", AutoSize = .T.

Procedure Load

* this represents your course table

Create Cursor mycoursesTable (courseID i, courseName c(10))

Insert Into mycoursesTable Values (1,'SE')

Insert Into mycoursesTable Values (2,'VFP')

Insert Into mycoursesTable Values (3,'ASP')

Endproc

Procedure cboCourse.Init

With This

.RowSourceType = 3 && SQL

.RowSource = 'select courseName,courseId from myCoursesTable into cursor crsCourse'

.Style = 2

Endwith

Endproc

Procedure cmdShowSelected.Click

if thisform.cboCourse.ListIndex # 0

Messagebox("You selected course "+;

crsCourse.courseName - " with ID:" - Transform(crsCourse.courseID))

else

MessageBox('No selection')

endif

Endproc

Enddefine






Re: Locate Command

Ahsan Amin

yes i am doing the same but pointer is not moving





Re: Locate Command

Ahsan Amin

i am already using a form so if you could tell me in another easy way. At the time what happening here is it's showing first row of the combo empty and when i select any value from it, it moves to top and show duplicate value and ID remains the same





Re: Locate Command

CetinBasoz

If you are doing the same then pointer does move.





Re: Locate Command

CetinBasoz

That is the easiest way I know.




Re: Locate Command

hangover

Ahsan Amin wrote:
i am already using a form so if you could tell me in another easy way. At the time what happening here is it's showing first row of the combo empty and when i select any value from it, it moves to top and show duplicate value and ID remains the same

Try putting the following in the INIT event of your form:

Code Snippet

THIS.AddProperty ("aCourseType[1]")

SELECT CourseName, CourseID ;

FROM a_courses ;

ORDER BY 1 ;

INTO ARRAY THIS.aCourseType

WITH THIS.cboCourse

.RowSourceType = 5

.RowSource = "THISFORM.aCourseType"

.BoundColumn = 2

.BoundTo = .T.

.Value = THIS.aCourseType [1, 2]

ENDWITH

THISFORM.cboCourse.Value should return the CourseID

Dom