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

VFP 6 - getting more than 1 value returned from a combo box 1

Status
Not open for further replies.

wetton

Technical User
Jun 26, 2006
42
AU
Is it possible say, from showing a list of names in a combo , each of which have id numbers in another field or element in an array , to easily include the id in a variable after selection of a name in the combo.

Many thanks

PW
 
Yes,
Use a multi-dimensional array, with each element being a seperate column. So if you have the following infromatin:

Bob Smith 12134
Mary Jane 12135
Tim Thomas 13333

As an array, there are 3x3 elemnts. this.array(1,1) = Bob
with an array the first number represnets your row, while the second represent the column. So your data source has to reference the array properly. (2,1), (1,1) or (3,1) if you want the last name in your combo box.

THEN, once you've selected them, simply pluck the other array element out of the row. If you select "Jane" you now know you have array row 2, column 2 and you then want row 2, column 3 for the ID.

Simply assign it on your ClickEvent:

oMyObject.Value = This.Array(ListItem,3)
will assign the value of the 3rd array element from row 2 (based on the ListItem which will be equal to the number of the item you just selected, and therefore equal to the row number).


You'll need to play with the Combo Box control some to get the full grasp. If you've not dealt with array's before, they are just like dealing with a table in memory, where you reference them by row and column number. (Like Excel).



Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Thanks Scott,

I understand your answer - many thanks

PW
 
I do find a problem with

Code:
Simply assign it on your ClickEvent:

oMyObject.Value = This.Array(ListItem,3)
My combo is called cboNames
My array is called aMyNameList and the builder has placed this in RowSource
NumberOf Elements =ALEN(aMyNameList)
ColumnCount =ALEN(aMyNameList,2)


- I can't find a way to work these in ( substitute) in your statement.

I can obviously use [name1 = this.value] where I get the assigned element value in my case [1,1]

but if I want to find name2 I am still confused.

Sorry.

PW

 
First, you don't need to set NumberOfElements; that's a backward compatibility item.

Set BoundTo to .T., so that the combo can work with numeric values. Set BoundColumn to 3, and you won't need any code to have the value of the combo be the id of the selected item.

Then, in any code where you need the id, you can just cboName.Value.

Tamar
 
Hi Guys

I decided on

click event

element = this.listitemid
myname = aMyNamelist[element,1]
myid = aMyNamelist[element,2]
myno = aMyNamelist[element,3]

Many Thanks

PW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top