This project is read-only.

Validate not firing sometimes

Dec 6, 2010 at 3:33 PM

I have a collection of users.  I then iterate through the list and add an event handler for each of the Validate, PropertyChanging and PropertyChanged events as shown in the code stub below.  If I directly affect any instance and do a persist it will fire all three events as expected.  However, going through the BindingSource, BindingNavigator and DataGridView I will only ever see the PropertyChanging and PropertyChanged events.  When I click the SAVE button and do a persist it will not fire the Validate.

        Private dbColl As TTE.CALTRACK.Business.Objects.TTEUSERCollection
        dbColl = TTE.CALTRACK.Business.Objects.TTEUSERCollection.RunSelect("ORDER BY USERID")
        Dim myList As List(Of TTE.CALTRACK.Business.Objects.TTEUSER) = dbColl.ToList
        For Each inst As TTE.CALTRACK.Business.Objects.TTEUSER In myList
            AddHandler inst.Validate, AddressOf dbuser_Validate
            AddHandler inst.PropertyChanging, AddressOf dbuser_PropertyChanging
            AddHandler inst.PropertyChanged, AddressOf dbuser_PropertyChanged
        BindingSource1.DataSource = myList
        BindingNavigator1.BindingSource = BindingSource1
        DataGridView1.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged
        DataGridView1.DataSource = BindingNavigator1.BindingSource

I stepped through the debugger and I can see that the Validate property in each instance is set right after doing the AddHandler steps, but it appears that by the time the DataGridView gets to doing anything the Validate property is null again.

Any thoughts on what I could be doing wrong?  The persist is definitely working.

Dec 7, 2010 at 6:03 PM

I assume this is in a web application since you are using the DataGridView. In a web application the state is always disconnected. If you are binding this on the page load (no postback) and then pressing the Save button (causing a postback) in which you do not reload the page, you will not get any events. I would have to see all your code to know for sure. The events are only hooked up for the time the page is loading memory. If you are expecting to get a button press postback and still have the events hooked, you will will find this is not possible. You will need to come up with some other scheme. you can laod the grid on each page loda, no matter if postback or not. This would ensure that the event were hooked up. I am assume you are only load the grid on non-postbacks. Is this the case?