FIX: Data Bound User Control Updates Only First Bound Column (812918)
The information in this article applies to:
- Microsoft ADO.NET (included with the .NET Framework) 1.0
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2002)
SYMPTOMSWhen you try to update more than one column of a table by
using a bound user control that has multiple bound properties, only the
modified data for the first bound property is updated in the table. You may
notice this behavior only for the first row of the table.WORKAROUND To work around this problem in ADO.NET 1.0, call EndCurrentEdit to end the current edit operation for all the bound controls. You
can call EndCurrentEdit in the Validating event of each bound control, or you can call the OnValidating event of the UserControl class as demonstrated in the following code: Call EndCurrentEdit in the Validate Event of UserControlAppend the following code to the UserControl1 class: Visual Basic .NET Code ' Override the OnValidating of a Control
Protected Overrides Sub OnValidating(ByVal e As System.ComponentModel.CancelEventArgs)
' Iterate through each bound object and then end the current edit
Dim b As Binding
For Each b In Me.DataBindings
Dim cm As CurrencyManager = b.BindingManagerBase
cm.EndCurrentEdit()
Next
End Sub Visual C# .NET Code // Override the OnValidating of a Control
protected override void OnValidating(CancelEventArgs e)
{
// Iterate through each bound object and then end the current edit
foreach (Binding b in this.DataBindings)
{
CurrencyManager cm =(CurrencyManager)(b.BindingManagerBase);
cm.EndCurrentEdit();
}
} Call EndCurrentEdit in the Validating Event of Each Control That Is Used in UserControlAdd the following code to the Validating event of the control that is used in the UserControl class. For example, when you use a TextBox control in your UserControl class, add the following Validating event code for the TextBox1 control: Visual Basic .NET Code ' Validating event of First control
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
m_Property1 = TextBox1.Text
OnValidating(e)
' Iterate through each bound object and then end the current edit
Dim b As Binding
For Each b In Me.DataBindings
Dim cm As CurrencyManager = b.BindingManagerBase
cm.EndCurrentEdit()
Next
End Sub
Protected Overrides Sub OnValidating(ByVal e As System.ComponentModel.CancelEventArgs)
End Sub
Visual C# .NET Code // Validating event of First control
private void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
m_Property1= textBox1.Text;
OnValidating(e);
foreach (Binding b in this.DataBindings)
{
CurrencyManager cm =(CurrencyManager)(b.BindingManagerBase);
cm.EndCurrentEdit();
}
}
protected override void OnValidating(CancelEventArgs e)
{
} STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
This bug was
corrected in ADO.NET version 1.1 for data binding.
REFERENCES For additional
information, click the following article number to view the article in the
Microsoft Knowledge Base: 313482
INFO: Roadmap for Windows Forms Data Binding
Modification Type: | Major | Last Reviewed: | 1/22/2004 |
---|
Keywords: | kbDataview kbDataBinding kbfix kbControl kbSystemData kbCtrl kbWindowsForms KB812918 kbAudDeveloper |
---|
|