Data bound Combox not updated with edited data

Napivo1972

Regular
Joined
Aug 31, 2004
Messages
85
Hi,

It’s been a while since I posted here… I have been away from programming for a while.

I have a problem with a data bound combo box. I included the forms load event where I do all the bindings.

I have a form with a combo box cmbTVARates and 2 textboxes txtValue and txtName

I use the combo box to select a record but I don’t edit in it. The data is send to the 2 textboxes where I edit the data and then save it. This works like a charm but while the data is saved to the datatable and even saved to the database, the combo box is not updated with the new names and added rows.

I have tried breaking and restoring data bindings, call refresh, update or even invalidate but nothing seems to work.

Anyone have an idea?

Visual Basic:
Private Sub frmTVA_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dv = New DataView(Startup.DB.t_TVA.DataTable)
        dv.Sort = "ID"
        Dim b As Binding

        cmbTVARates.DataSource = dv
        cmbTVARates.DisplayMember = "Name"
        cmbTVARates.ValueMember = "Value"

        b = txtValue.DataBindings.Add("Text", dv, "Value")
        AddHandler b.Format, AddressOf SingleToPercent
        AddHandler b.Parse, AddressOf PercentToSingle

        txtName.DataBindings.Add("Text", dv, "Name")

        ' Specify the CurrencyManager for the DataView.
        cm = CType(Me.BindingContext(dv), CurrencyManager)
        AddHandler cm.CurrentChanged, AddressOf CM_CurrentChanged
        AddHandler cm.ItemChanged, AddressOf CM_ItemChanged
        AddHandler cm.MetaDataChanged, AddressOf CM_MetaDataChanged
        AddHandler cm.PositionChanged, AddressOf CM_PositionChanged
    End Sub
 
I'm not 100% sure whether this is your issue, but there is no need to create a new DataView. Simply bind your ComboBox to the DataTable itself. When you do this, the ComboBox is actually bound to the DataTable's DefaultView property, which is a DataView. You then apply any filtering or sorting to Startup.DB.t_TVA.DataTable.DefaultView and you should find that all is well with the world.
 
The issue is that when my data gets edited the combo box does not reflect the changes.

I solved this by adding items to the combo box myself. So now it’s unbound and I can choose when to update. It works like a charm.

About the data view. I put all database access in a single class. So I only load a table once in my application. Tables can be used in different forms. I rather dislike one form changing the sort order of another form or even worse changing the row filter and not showing all records. This happens if you use the default view.
 
Back
Top