Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Right way with combo box control?
Message
From
02/06/2008 13:07:07
 
 
To
02/06/2008 10:26:19
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01320984
Message ID:
01321050
Views:
45
This message has been marked as the solution to the initial question of the thread.
>Firstly: on a form, after I append a blank, I want to set a default value for a combo box. Should I a) update the view field that it is bound to or b) stuff the control with the value to be found (they both seem to work but wondering if one is better than the other or does it matter)

I think a) is a better choice.


>Secondly: this combo gets it's rows from an array that is 5 columns and a few rows wide; first column is the display (a name) and second column is an ID number for the user (numeric); so I have it bound to the 2nd column and the control source of that is a numeric field in a view; that worked on an edit right off but was having trouble when I defaulted to a value on an append blank (the control would not display the name that it was supposed to default to).
>
>I got this working by changing "BoundTo" to .T. - but I find the help quite confusing - I just wanted to know why this setting was ncessary and what it was doing. Can anyone explain to me what this means and/or what it is doing?

All data in a combo is stored as character in the combo. So when you bind a combo to a numeric item (field, variable, property), the combo assumes that the value is the index (ListIndex) of the selected item, not a data field. Setting BoundTo to .T. turns off that assumption and allows you to bind numeric data.


>Finally, when I check the control's properties at run time, List and ListItem are always empty character and ListIndex and ListItemID are numeric and are set to the row contained in the array (numeric). If I want to access the other columns in the array (cols 3 and 4 contain birthdate etc), should I used ListIndex or ListItemID to access them (or does it not matter if the list is static).

Combos (and listboxes, to which everything I've said in this message also applies) have two internal representations. List and ListIndex reference one of them; this representation is in the order items are shown in the combo. When you add or remove items from the list, the index of an existing item can change.

ListItem and ListItemID use what you can think of as primary keys. When you add an item, it's assigned an ItemID; it keeps that ItemID as long as it stays in the list.

You can use either set to look at the data, but always use ListIndex with List, or ListItemID with ListItem.

If you have the Hacker's Guide, you can read a lot more about this. Start with the "Combobox, Listbox" topic, and then read the "AddItem ..." topic.

Tamar
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform