Hi,

I have written a program that binds controls on a form to fields of a table in a Microsoft Access database.One of the controls on the form is a combo box that is binding to table called Type_T which contains one column called Type.

i need to update the combo box whith the new values when i update the table Type_T. the addition of the table going fine and i see the record updated, but the combo box remain without changes.

I have tried this code :

Me.ComboBox2.DataSource = Nothing
                Me.ComboBox2.DataSource = Me.DataBaseDataSet.Type_T
                'Me.ComboBox2.DataSource = Me.TypeTBindingSource
                Me.ComboBox2.DisplayMember = "Type"
                Me.ComboBox2.ValueMember = "Type"

but nothing happened.

I have tried this also:

Dim bd As Binding
                 bd = New Binding("Text", ds, "Type_T.Type")
                 Me.ComboBox2.DataBindings.Add(bd)

there were no changes in the combo box.

in addition, this was my last attempt to update it which is to call ReFillCombo()

Private Sub ReFillCombo()
        Me.ComboBox2.Items.Clear() ' Clear the items of the combobox
        Dim constr As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\HST\My Documents\Visual Studio 2005\Projects\Invoice\Invoice\DataBase.mdb"
        Dim conn As New OleDb.OleDbConnection(constr)
        Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM Type_T", conn)
        Dim dt As New DataTable
        da.Fill(dt)
        Me.ComboBox1.DataSource = dt
        Me.ComboBox1.DisplayMember = "Type"
        Me.ComboBox1.ValueMember = "Type"
    End Sub

and it gives me this error: Items collection can not be modified when the datasource property is set.

every time i have to close the application and re run it again to see the updat in the combo box.

please help me !!

Try THis:
======

Me.ComboBox1.DataSource = dt 'Can be any other table
Me.ComboBox1.DisplayMember = "Type"
Me.ComboBox1.ValueMember = "Type"
Me.ComboBox1.Refresh()

I have already tried that.
nothing yet different.

i have the same problem with datagridview, dont display what i have add.


If posting the whole code here help, let me know.

check out,whether u have written checkbox function-inside the if(page.isnotpostback)
regards,,
preetham

Hi

i found the solution :)... it was in this code:
e.ComboBox2.DataSource = ds.Tables("Temp_table")

rather than:
e.ComboBox2.DataSource = ds

Thank you all for your help
i really appreciate it

can you show me what your complete code for these lines look like

Private Sub ReFillCombo()
Me.ComboBox2.Items.Clear() ' Clear the items of the combobox
Dim constr As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\HST\My Documents\Visual Studio 2005\Projects\Invoice\Invoice\DataBase.mdb"
Dim conn As New OleDb.OleDbConnection(constr)
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM Type_T", conn)
Dim dt As New DataTable
da.Fill(dt)
Me.ComboBox1.DataSource = ds.Tables("Temp_table")
Me.ComboBox1.DisplayMember = "Type"
Me.ComboBox1.ValueMember = "Type"
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.