· Hi all,
I am trying to do a simple databindingwith a ComboBox and have found that DataSourceUpdateMode.OnPropertyChanged does not work as expected. But if I change it to DataSourceUpdateMode.Never then the combobox updates without any problems. Best to explain after my code:
These are the datatables im using which are both under DocumentsDataSet
Documents
id
typeID
....
....
DocumentTypes
id
description
…………………………………………………………………�/span>
public class DocumentViewControl
{
public DocumentViewControl()
{
InitializeComponent();
}
private void InitializeComponent()
{
//......
//......
this.documentsDataSet = new DocumentsDataSet(); //contains tables Documents and DocumentTypes
this.documentsBindingSource = new BindingSource();
//
// documentsBindingSource
//
this.documentsBindingSource.DataMember = "Documents";
this.documentsBindingSource.DataSource = this.documentsDataSet;
//
// documentTypesBindingSource
//
this.documentTypesBindingSource.DataMember = "DocumentTypes";
this.documentTypesBindingSource.DataSource = this.documentsDataSet;
// cboDocumentType
//
this.cboDocumentType.DataBindings.Add(
new System.Windows.Forms.Binding(
"SelectedValue", this.documentsBindingSource, "typeID", true,
System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged
)
);
this.cboDocumentType.DataSource = this.documentTypesBindingSource;
this.cboDocumentType.DisplayMember = "description";
this.cboDocumentType.ValueMember = "id";
//
// .... and then initilization code for the text boxes which does not have any problems, so im not including the code here
}
public void LoadData(int documentID)
{
DocumentsTableAdapter documentsAdapter =
new DocumentsTableAdapter();
DocumentTypesTableAdapter documentTypesAdapter =
new DocumentTypesTableAdapter();
documentsAdapter.FillByDocumentID(documentsDataSet.Documents, documentID);
documentTypesAdapter.Fill(documentsDataSet.DocumentTypes);
documentsBindingSource.ResetBindings(false);
}
}
public partial class frmMainForm : Form
{
public frmMainForm()
{
InitializeComponent();
}
private void frmMainForm_Load(object sender, EventArgs e)
{
documentViewControl1.LoadData(1);
}
}
..........................................................
The problem is, when the form is loaded, it shows all the text boxes with appropriate values (as expected), but not the combo boxes. The comboboxes are loaded with the values from the DataSource, but always pointing to the first value in the list rather than what the actual value is.
But if i change the databinding code for the combo box from DataSourceUpdateMode.OnPropertyChanged to DataSourceUpdateMode.Never then it works.
What is going on? Isn't DataSourceUpdateMode.OnPropertyChanged supposed to update the combo box once the value in the underlying table/view has been updated?