Thursday, January 12, 2006
Replacing IdleSync() w/ OnListChanged()
Environment: CLSA .NET and Windows Form
The original sample code illustrated the use of Application.IdleSync() to toggle the save button in a BusinessBaseCollection when editing a specific editable object. I've noticed when the mouse is moved the application.IdleSync() handler is triggered and I find it ineffecient.
Trying to find an efficient way, I noticed that BusinessBaseCollection overrides the OnListChanged Event. So I changed my IdleSync handler to OnListChanged.
See below for illustration:
In windows form level, I've created a method name OnListChanged()
btnSave.Enabled = mCustomer.IsSavable
'Add the code for the Broken Rules Error Provider
End Sub
After retrieving records from the database, pattern this code just replace it with your own variables.
'Needs to be remove first
RemoveHandler mCustomer.OnListChanged, AddressOf OnListChanged
AddHandler mCustomer.OnListChanged, AddressOf OnListChanged
Before closing the form alway remove the added handler, it can be placed on Form_Close() event.
RemoveHandler mCustomer.OnListChanged, AddressOf OnListChanged