Adding Validation to a Dataset - ColumnChangingEvent does not fire RRS feed

  • Question

  • I am following Beth Messi's forms over data video series.

    In the video "How Do I: Add Validation?" she is putting a piece of custom validation code into the (customer) dataset.

    She is using VB. I am however using C# so I tried to find a piece of code in C# which can do the same in my "tbPersonsAssignmentsDataSet "- This is the code I have used (Taken from MSDN and modified): 

    namespace PMforms2._0V1._0._0._1 { //BEGIN
    public partial class tbPersonsAssignmentsDataSet {

            partial class tbPersonsAssignmentsDataTable
                // C#
                // Add this code to the DataTable
                // partial class.

                public override void EndInit()
                    // Hook up the ColumnChanging event
                    // to call the SampleColumnChangingEvent method.
                    ColumnChanging += SampleColumnChangingEvent;

                public void SampleColumnChangingEvent(object sender, System.Data.DataColumnChangeEventArgs e)
                    if ((string)e.ProposedValue == "B")
                        e.Row.SetColumnError("ProjectID", "Something is wrong");
                        e.Row.SetColumnError("ProjectID", "");

    } //END

    The problem is that I cant get the columnchange event to fire. I want the code to issue an error if the letter B is entered in a (ProjectID) column.

    Can anyone provide me with some guidence?

    Monday, May 14, 2012 8:24 AM