Link to home
Start Free TrialLog in
Avatar of dslocum
dslocum

asked on

Updating Combo list after inserting new record

Hi,
I have a form that has a combo box who's list has Customers.  This is bound to a data adapter during form load.  The code is:

            daCustList.Fill(DataSet11)

I have a button that brings up a New Cutomer form that successfully adds a new Customer to the database.  No problem from a DB standpoint.

Once the new customer is added however, I need to refresh the Customer combo box list to show the newly added customer.  If I .Fill again, the list is appended to.

 I can't figure out how to do this, so help is appreciated.  I hope I'm using the DataAdapter & ComboBox correctly.

Regards,

Doug
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

To refresh instead of append

daCustList.MissingSchemaAction = MissingSchemAction.AddWithKey
daCustList.AcceptChangesDuringFill = True
Avatar of dslocum
dslocum

ASKER

BriCrowe,

Thanks. Your suggestion still doesn't cause my original ComboList to include the new Customer in the list, at least in my situation.  Is there another step I need to do after your code ?  

Thanks,

Doug
you may need to rebind your combobox to the dataadapter
Avatar of dslocum

ASKER

BriCrowe,

Still having probs.  My code is:

    Private Sub btnCustNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustNew.Click
        Dim FrmCust As New frmCustomer

        Try
            With FrmCust

                .ShowDialog()      'Add new customer to DB

                daCustList.MissingSchemaAction = System.Data.MissingSchemaAction.AddWithKey
                daCustList.AcceptChangesDuringFill = True
                cboCustName.Rebind()     'Added per your last suggestion

            End With

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

FYI, If I close the app and then reopen, the new Customer DOES show in the combo list.

BTW, I'm not sure if it matters, but I'm using a ComponentsOne Combo box.  I guess that this should work the same as a standard ComboBox.

I appreciate your help to hopeffuly resolve this!

Doug
the lines...

daCustList.MissingSchemaAction = System.Data.MissingSchemaAction.AddWithKey
daCustList.AcceptChangesDuringFill = True

only need to be declared once for the dataadapter so you can put them in your form.load procedure

to rebind try this...
cboCustName.databindings.remove(cboCustname.databindings("Text"))
cbocustname.databindings.add("Text", myDataSet.myDataTable, "ColumnName")

Avatar of dslocum

ASKER

Hello again,

I added a Watch to the C1 ComboBox, and it appears that there are no databindings, so the technique above isn't working.  When I stated my problem originally, I thought that the control was bound.  Is there some other .NET technique that is being used?

The design-time C1 control properties are set to:

DataSource = DataSet11
DataMember = ARCUSFIL_SQL    'This is the table with the appropriate SQL Select to fill the combo's list
DisplayMember = CustName
ValueMember = Cus_No

I don't necessarily expect that you know this C1 combo control, but can you recognize the technique that is used and continue to help with my goal?

Thanks for your time and patience.

Doug
ASKER CERTIFIED SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial