Updating a combo box immediately

Roman_Candle

Member
Joined
Jan 19, 2005
Messages
10
Programming Experience
Beginner
i have a combo box on a form.
when you select an item from it the rest of the form is populated(ie a search function)

i can also add a new record on the form.
what i want is for the new record i add to appear in the combo box straight away.

to originally populate the combo box i have been using a block of code i place in the form load.so i decided to take this block of code and place in a sub procedure and call it when i add a record instead.however it doesnt seem to update straight away unless i exit the form and then go back into it!

am i going about this the right way?
 
current code

this is what i have been using to populate the combo box from form load.but i decided to put it into a sub procedure to call it in the INSERT statement.


VB.NET:
[size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] UpdateComboBox1()
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] conn = [/size][size=2][color=#0000ff]New[/color][/size][size=2] OleDbConnection(conn1)
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] ds1 [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] DataSet()
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] dt [/size][size=2][color=#0000ff]As[/color][/size][size=2] DataTable
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] dr [/size][size=2][color=#0000ff]As[/color][/size][size=2] DataRow
 
da1.Fill(ds1)
 
cboYearlyStuff.Items.Clear()
 
 
 
[/size][size=2][color=#008000]'Repeat for each table in the DataSet collection.
 
[/color][/size][size=2][color=#0000ff]For[/color][/size][size=2][color=#0000ff]Each[/color][/size][size=2] dt [/size][size=2][color=#0000ff]In[/color][/size][size=2] ds1.Tables
 
[/size][size=2][color=#008000]'Repeat for each row in the table.
 
[/color][/size][size=2][color=#0000ff]For[/color][/size][size=2][color=#0000ff]Each[/color][/size][size=2] dr [/size][size=2][color=#0000ff]In[/color][/size][size=2] dt.Rows
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] strMyJoin [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String
 
[/color][/size][size=2]strMyJoin = (dr("Yearly_ID")) & " - " & (dr("TheYear")) & " - " & (dr("MyClass"))
 
cboYearlyStuff.Items.Add(strPupilJoin)
 
[/size][size=2][color=#0000ff]Next
 
[/color][/size][size=2][color=#0000ff]Next
 
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub[/color][/size]
 
[size=2][color=#0000ff]
[/color][/size]

it works when i call it from form load,but wont work for subsequent "callings"

VB.NET:
Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2][color=#000000] YearlyForm_Load([/color][/size][size=2][color=#0000ff]ByVal[/color][/size][size=2][color=#000000] sender [/color][/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#000000] System.Object, [/color][/size][size=2][color=#0000ff]ByVal[/color][/size][size=2][color=#000000] e [/color][/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#000000] System.EventArgs) [/color][/size][size=2][color=#0000ff]Handles[/color][/size][size=2][color=#0000ff]MyBase[/color][/size][size=2][color=#000000].Load[/color]
UpdateComboBox1()
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub[/color][/size]
 
[size=2][color=#0000ff]
 
Back
Top