Search code examples
vb6comboboxrefresh

What is the preferred method of refreshing a combo box when the data changes?


What is the preferred method of refreshing a combo box when the data changes?

If a form is open and the combo box data is already loaded, how do you refresh the contents of the combo box without the form having to be closed and reloaded?

Do you have to do something on the Click event on the combo box? This would seem to be a potential slow down for the app if there is a hit to the database every time someone clicks on a combo box.


Solution

  • You must determine:

    1) When does you data change?

    If it depends on other users activity, so you can't determine whether it's changed without querying DB, you can figure out an optimal time for a refresh, like form loading or on every click, or you can use a timer control to refresh the data in a specific time.

    2) When does your user need to know about that change?

    Try to understand how urgent it is for the user to know about a change. Talk to them. Depending on that, decide when do you need to refresh your data.

    Finally:

    There isn't a correct way of doing that. It depends on a software structure, users' needs and on a specific situation.

    Hope it helps. Good Luck!

    UPDATE:

    I can add a solutions, that I used recently. If something won't be clear, just ask.

    I assume, your refreshing the combo from MS SQL Server.

    If so,

    1. Create a table , storing in it Combo's data changing date or a version.

    2. onClick event or using timer control, which will check for changes every 5 minutes(or any other time), you can compare last change date (or version) of your combo with last change(or version) in that table we store last date(or version) and only if the date(or version) was changed, refresh the combo.

    3. Last date (or version) you can store in a variable or in a textbox control, changing it's value every time you refresh the combo.

    4. Update last date(or version) in that table if the data changes.

    In this case, you'll just need to check for changes, not update them.

    P.S. If this solution doesn't feet you, just refresh every time on click event. There's no better event for that case.