Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataSourceUpdateMode.OnPropertyChanged - How is it supposed to work?
 

DataSourceUpdateMode.OnPropertyChanged - How is it supposed to work?

· 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?

  • Changed TypeKayes Thursday, September 24, 2009 2:25 AM
  •  
Kayes  Thursday, September 24, 2009 2:24 AM
Other way round, the datasource update mode defines how the underlying data source is uüpdated where the bound control changes it's value

<Quote from MSDN Help>

When a control is bound to a data source using a Binding object, you can specify when an update to the data source will occur using the DataSourceUpdateMode enumeration.

When the update mode is Never, you can force the data source to be updated by using the WriteValue method.


<Quote>

In order to update the combo box you need to requery the database or whatever datasource you have.
Christoph Wagner  Friday, September 25, 2009 12:55 PM
Other way round, the datasource update mode defines how the underlying data source is uüpdated where the bound control changes it's value

<Quote from MSDN Help>

When a control is bound to a data source using a Binding object, you can specify when an update to the data source will occur using the DataSourceUpdateMode enumeration.

When the update mode is Never, you can force the data source to be updated by using the WriteValue method.


<Quote>

In order to update the combo box you need to requery the database or whatever datasource you have.
Christoph Wagner  Friday, September 25, 2009 12:55 PM

You can use google to search for other answers

Custom Search

More Threads

• add new record with autoincrement field error
• SQL and DataGrid
• date format problem
• Out of memory
• Disabling small trangular glyphs in the row header
• Getting value of CheckBox field in DataGridView
• How Do I Update The Database From The DataGridView?
• Datagridview : Select Multiple rows and process 1st cell
• Updating datagridview, a few questions.
• calling VB dll method from VC++