Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

 

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

Posted
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.
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...