Link to home
Start Free TrialLog in
Avatar of ol muser
ol muserFlag for United States of America

asked on

combo box edit best practice

Hi, I am using c# combo box controls where I would like to allow the users to enter new values. i.e I have the DropDownStyle = DropDown. For example, I have a combo box that allows users to select/enter the country code. While loading the form I set the dataset for the combobox by querying database for the code and displaytext for the countries. User can either select an existing country code or enter a new one. Please don't ask why I can't pre populate the combo box with all possible country codes as it is a finite set with infrequent changes, it is the customer requirement and besides there are several controls like this (test center, etc).

Now the way currently the combo box works is, if the user types in a new entry, I add the new value to the database and refresh the dataset. I do this so the new entry has a proper unique code in the database. This slows down the application a bit though it is not a frequent operation. Currently I also set the AutoCompleteMode property to SuggestAppend. This is to prevent users from adding a duplicate entry or entering misspellings of existing entries.

What is the best practice in this regard? Is it better to add new entries in memory and add them to the database at a later stage? It is a multi-user application and it is also possible someone else could also be adding the same entry though it is rare.
Avatar of AngryBinary
AngryBinary

Is this an Internet or an intranet application?

For intranet, I think what you are doing is fine. You may want to prevent race conditions on inserts by doing new value inserts via a stored proc that validates that the value doesn't exist and inserts atomically.

Storing the values in memory for later add because it adds a bit of complication to the application. You would have to implement, for instance, an IHttpModule Dispose event to ensure delivery of values, and even then that isn't reliable in the case of a server crash or hardware failure (which, based on the description of the client's requirement, seems like it would be a reasonably acceptable loss). It also implies you would have to maintain a cache in server memory of all country code values, otherwise building the data set would be complicated if you had to refer to two different data sources (one from the database, one from memory). IMO, this is more engineering than should be required for a simple feature like this.

It's a little difficult to believe that the slowdown is that significant as a result of adding a country-code value. What is more likely is that it adds an additional post back to the process of filling out a form, and this can likely be avoided by either performing the new value insert along with the rest of form processing, or by doing so via AJAX.
Avatar of ol muser

ASKER

Sorry I forgot to add this. This is a windows forms application running on WinXP possibly running on Win7 someday, both 32 bit.
ASKER CERTIFIED SOLUTION
Avatar of AngryBinary
AngryBinary

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AndyAinscow
Have you asked the client how they intend to cope with incorrect entries?

eg.
You have En  England as a choice but someone accidentally types in Em then adds a new entry for England.