Problem with simple DataBinding and Validation with Cancel=true still updates DataSource - by TrickAbort

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


8
0
Sign in
to vote
ID 490267 Comments
Status Closed Workarounds
Type Bug Repros 2
Opened 9/16/2009 3:15:58 PM
Access Restriction Public

Description

A TextBox Control has a simple DataBinding.  When the TextBox Validating Event detects an error, sets e.Cancel=True and exits, the DataSource is incorrectly updated with the invalid data.

Demo program...
1) creates a simple Bind between a TextBox and a test object.
2) defines a Validating event on the TextBox
3) Validating event detects the blank field and sets e.Cancel=true.

Sample Code:

Public Class Form1
    Private _anObject As New aClass

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox1.DataBindings.Add(New Binding("Text", _anObject, "myProperty"))
    End Sub

    Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
        Debug.Print("Validating: ctrl:'{0}'  obj:'{1}", TextBox1.Text, _anObject.myProperty)
        If TextBox1.Text = "" Then
            Debug.Print("Set Cancel=true; should not update bound object")
            e.Cancel = True
        End If
    End Sub
End Class

Public Class aClass
    Private _myProperty As String = "aaaa"
    Public Property myProperty() As String
        Get
            Return _myProperty
        End Get
        Set(ByVal value As String)
            Debug.Print("Updating: _myProperty:'{0}'  value:'{1}'", _myProperty, value)
            _myProperty = value
        End Set
    End Property
End Class
Sign in to post a comment.
Posted by lanwake on 1/7/2014 at 2:07 PM
It is completely ridiculous that this bug has not yet been fixed (2014)!
Just lost 3 hours trying to debug my code because of this.
Posted by Microsoft on 9/20/2009 at 6:50 PM
Thanks for reporting the issue.

Customer feedback is a critical part of a successful, impactful product release. Unfortunately another part is the reality of schedules and the need to get the bits into production. We have evaluated the issue that you reported and it does not meet the criteria to be addressed in this release. This evaluation is carefully done and considers many aspects including fix cost, breaking changes, globalization, performance, etc.

Many customers have found it useful to discuss issues like this in the forums (http://forums.microsoft.com/msdn/default.aspx?siteid=1) where Microsoft and other members of the community can suggest workarounds.

Before we even begin work on the next release of the NET Framework release where we can make changes like this one we will devote time to addressing the top issues/suggestion (in terms of number of votes, lack of workarounds, etc). So please do continue to vote for this item if it is causing issues.

Thanks,
UIFx Team
Posted by Microsoft on 9/18/2009 at 12:33 AM
Thanks for your feedback. We are routing this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team