Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
User adding in a Combobox
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00856254
Message ID:
00856348
Vues:
21
Hi Raymond.

I want the user to be able to add in a new item (not in already in Table_B)and to have that item added to Table B.
How can I do that?


This is some of what we had to say on the topic in 1001 Things You Wanted to Know About Visual FoxPro:

Adding a new item to a ComboBox with style = 0-DropDown Combo is a pretty straightforward process because the control's Valid event fires whenever a selection is made from the list and again before it loses focus. When a user has typed something that is not in the current list, the control’s DisplayValue property will hold the newly entered data but the Value property will be empty. A little code in the Valid method of the control allows you to determine whether the user selected an item in the list or typed a value not in the list. For example the following code could be used:
IF  NOT( EMPTY( This.DisplayValue ) ) AND EMPTY( This.Value )
  *** The user has typed in a value not in the list
However, this will not be reliable if the RowSource allows for empty values so a better solution is to use either:
IF  NOT( EMPTY( This.DisplayValue ) ) AND This.ListIndex = 0
You must then take action to add the new item to the control's RowSource. The code used to do this will be instance specific, depending on how the control is populated. If the combo's RowSourceType is "0-None" or "1-Value," use the AddItem or AddListItem method to add the new value to the list. If the RowSourceType is "2-Alias," "3-SQL Statement" or "6-Fields," the new item must be added to the underlying table and the combo or list box requeried to refresh its internal list. For RowSourceType "5-Array," add the item to the array and requery the control.
Although it is simple enough to add a new item to a DropDown Combo, this simplistic solution may not be adequate. If the only requirement is to add a new description along with its primary key to a lookup table, the methodology discussed above is up to the task. Much of the time, however, a lookup table contains more than two columns. (For example, the lookup table provided with the sample code for this chapter has a column for a user-defined code.) Additional fields may also need to be populated when a new item is added to the combo box.

We must also consider the fact that there is no quick and easy way to add new items to a ListBox. Considering how similar the ComboBox and ListBox classes are, we think it is appropriate that they share a common interface for adding new items. If the end-users add new items in the same manner, they have one thing to remember instead of two. The cboAddNew and lstAddNew classes provide this functionality through a shortcut menu invoked by right clicking the control. This shortcut menu also provides edit functionality. More often than not, if an item in a combo or list is misspelled, the user will realize it when he is selecting an item from the list. It is much more convenient to fix the mistake at this point, than having to use a separate maintenance form.

We created cboAddNew as a subclass of cboQuickfill to achieve a more consistent user interface. All of our custom combo box classes inherit from our quickfill combo class, so all behave in a similar manner. This type of consistency helps makes an application feel intuitive to end users.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform