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.
LVL 1
ol muserTechnology GeneralistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AngryBinaryCommented:
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.
0
ol muserTechnology GeneralistAuthor Commented:
Sorry I forgot to add this. This is a windows forms application running on WinXP possibly running on Win7 someday, both 32 bit.
0
AngryBinaryCommented:
OK, though I don't think that changes the concept much.

So, they add a new value, and you're saying that there's, for instance, a hiccup in the UI as a database call is made? You can make the call asynchronously, or on a different thread. But, I'm doubtful as to whether that's even advisable. At some point, I imagine the user will have to commit the values that they've entered to a database, so that would be the ideal moment to insert a new value.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.