Update item in Combo box automatically

brucelim80

Active member
Joined
Apr 20, 2006
Messages
35
Programming Experience
Beginner
hi ,

Does anyone know how to write a code to automatically update the items of the checkbox (previously extracted from database) once detected any changes in the database without resetting the form?

Thank you:confused:

Regards,
Bruce
 
Can you please be a bit clearer about what you want? The title mentions a ComboBox while the thread mentions a CheckBox, and it's not clear what's required anyway. Feel free to write more than one sentence if that's what it takes to provide a proper explanation.
 
Sorry my mistake.

It should be combo box.

I have a few items extracted from the database with the item selection in the combo box. Example when i click the combo box (countries) on the application i can see

USA
UK
Australia
Candana
VB.NET:
Sub Page_load
        Dim reader1 As OleDbDataReader = strSelect.ExecuteReader
        With reader1
            If .Read Then
                departtxt.Items.Add(.Item("countrycode").ToString)

                While .Read
                    departtxt.Items.Add(.Item("countrycode").ToString)

                End While
            End If
        End With
end sub
However at the other end, i had new countries added to the country database such as germany and spain. So it make up the list below

USA
UK
Australia
Candana
Germany
Spain

How do i write a code that automatically update the item in the combo box without user closing and opening the form?

Regards,
Bruce
 
Last edited by a moderator:
How are the new countries added to the country database? (I assume you mean the country table in the database)
If you are in control of adding the countries to the table, then adding them would be done the same as you've shown above
VB.NET:
departtxt.Items.Add("countryName")
 
Hi thank you for your respond.

The countries are added from another program.
Hence What i want is to have combo box updated automatically without refreshing the page again.

The page onload of the application form will get all the data in the database
If happen that the other program update the data in the database , the combobox must be able to update automatically while user is still in the midst of filling the form. That mean that the combobox is sychronizally updating its items everytime there is changes to the database


Is there a way to do this?

Regards,
Bruce
 
Is this a Windows app or a Web app? If it's a Web app then it's not a ComboBox, it's a DropDownList. If you use the correct names for things and post in the correct forum then confusion is avoided and you and we don't waste time on irrelevancies. There are ASP.NET forums for ASP.NET questions.
 
ASP.NET programs are written in VB.NET too. You stated ComboBox all along but you are also talking about refreshing pages, which makes it sound like a Web app. Refreshing pages has no meaning in Windows Forms. Also, if this is a question about Windows Forms specifically then it should have been posted in the Windows Forms forum. Moved.

As for your request, it sounds to me like your saying that if someone else changes the database you want your app to automatically update. That's just not happening I'm afraid. The database can't tell your app that data has changed. If your app wants data it has to initiate the action and go and get it. The best you can do is have your app intermittently query the database for new data. In that case you'd have to have a time stamp in each record to indicate when ti was last updated. You can then query the database for all records that have been updated since the last time you checked.
 
Well friend, I got your problem

Well friend, I got your problem, the best possible idea that I can think of is that you can check if the form that contains the said combobox has lost the focus and got focus back. If such a thing has happened refill the combo contents.
 
Back
Top