Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Databinding fails to update bound control on first load
 

Databinding fails to update bound control on first load

I have an interesting problem that I have been trying to figure out for a while now and I was hoping someone out there could point out the (most likely obvious) problem. I have code similar to the following.

Code Snippet

public void BindTestResultCodeDetails()

{

txtName.DataBindings.Clear();

if (mdsDetails.Tables.Count > 0)

{

if (mdsDetails.Tables[ResultRuleDA.TN_TEST_RESULT_RULE].Rows.Count > 0)

{

BindingContext[mdsDetails, ResultRuleDA.TN_TEST_RESULT_RULE].ResumeBinding();

txtName.DataBindings.Add("Text", mdsDetails.Tables[ResultRuleDA.TN_TEST_RESULT_RULE], ResultRuleDA.FN_TRR_NAME);

}

msdDetails is populated with a table named 'TestResultRule' with one rowwhena list box is populatedand the first item is selected in code.'TestResultRule' is the string value contained in ResultRuleDA.TN_TEST_RESULT_RULE. Looking at mdsDetails.Tables[ResultRuleDA.TN_TEST_RESULT_RULE].Rows[0][ResultRuleDA.FN_TRR_NAME] returns the expected value. However, at the end od the method call txtName.Text is still "". mdsDetails is populated in response to a mouse click on a list box after the form is displayed as well. When this happens - the binding happens as exprected. mdsDetails isainstance variable that isset to a valueimmediatelyprior to the above method beingcalled.Anyone got any suggestions?

Michael Fischer

_Michael Fischer_  Sunday, March 30, 2008 6:43 AM

Hi Michael,

Is the txtName visible when it is created?

If a control is not visible when it is created, and then it is bound to a data source, the value in the data source won't be pushed to the control and the value in the control won't be sent back to the data source either, even if we call the BindingManagerBase.EndCurrentEdit method. Once the control becomes visible, data binding will push the value in the data source to the control.

If this is not the case, could you please reproduce the problem in a simple project and send it to me? To get my actual email address, remove 'online' from my displayed email address.

Linda

Linda Liu  Wednesday, April 02, 2008 11:04 AM
Why did MS change this for SP1? It worked fine without the SP. I have a similar issue where the form worked fine for me but not a co-worker who has SP1 installed. I installed it, and now the form does not work on my machine anymore. Why would you take functionality away? Makes no sense to me. I am going on hour 6 of trying to find a way to update my dgv using the da. And yes all of the basics are covered for the update and select.

bob999999  Thursday, April 03, 2008 5:46 PM

You can use google to search for other answers

Custom Search

More Threads

• URGENT HELP - Binding Context for Combobox and TextBox
• DataGridView VerticalScrollbar Member
• getting error when passing parameter to stored procedure
• How to disable a DataGridViewRow? Need user selected rows to be visible yet disabled and darkened.
• Getting dynamic Column names
• DataGridView vs DataGrid vs VB6 DataGrid
• Hosting control in details view in a DataGridView
• Programmatically Bind a ComboBox in DataGrid from database
• datagrid
• TableAdapter.Insert and Identity