Hello,
I am having trouble trying to get UltraControlContainerEditor and my custom control to work properly. I have a couple of issues.
I have included a small sample project.
Bingo!
Awesome Mike, thanks a bunch. I didn't think of that.
Hi Jeff,
I went back and looked at my sample again and I see the problem. I was replacing the member variable with a new instance. But this means the control is still hooking the Changed event of the old instance and not the new one. So a better solution is to set the property so that the events get hooked/unhooked:
Private Sub Recurrence_PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Me.Recurrence = New clsRecurrence( mclsRecurrence.ScheduleID, mclsRecurrence.StartDate, mclsRecurrence.EndDate, mclsRecurrence.RunTime, mclsRecurrence.RecurrenceType, mclsRecurrence.Interval, mclsRecurrence.StartingTime, mclsRecurrence.EndingTime, mclsRecurrence.DayOfMonth, mclsRecurrence.Sunday, mclsRecurrence.Monday, mclsRecurrence.Tuesday, mclsRecurrence.Wednesday, mclsRecurrence.Thursday, mclsRecurrence.Friday, mclsRecurrence.Saturday, mclsRecurrence.MonthOfYear, mclsRecurrence.Instance ) Me.UpdateUI() Dim e2 As PropertyChangedEventArgs = New PropertyChangedEventArgs("Recurrence") RaiseEvent PropertyChanged(Me, e2) End Sub
Hi Mike,
Thanks for the reply.
That is what I had tried only fires on the first change after that the AfterCellUpdate event doesn't fire again for the same control instance.
I have changed to use CellChange event for instances of these custom controls.
It looks like my Equals/GetHashCode theory won't work. but creating a new object does.
I tried this out in a very limited test and it works fine for me.
All I did was change the Recurrence_PropertyChanged like so:
Private Sub Recurrence_PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Me.UpdateUI() Me.mclsRecurrence = New clsRecurrence( mclsRecurrence.ScheduleID, mclsRecurrence.StartDate, mclsRecurrence.EndDate, mclsRecurrence.RunTime, mclsRecurrence.RecurrenceType, mclsRecurrence.Interval, mclsRecurrence.StartingTime, mclsRecurrence.EndingTime, mclsRecurrence.DayOfMonth, mclsRecurrence.Sunday, mclsRecurrence.Monday, mclsRecurrence.Tuesday, mclsRecurrence.Wednesday, mclsRecurrence.Thursday, mclsRecurrence.Friday, mclsRecurrence.Saturday, mclsRecurrence.MonthOfYear, mclsRecurrence.Instance ) Dim e2 As PropertyChangedEventArgs = New PropertyChangedEventArgs("Recurrence") RaiseEvent PropertyChanged(Me, e2) End Sub
So basically, every time any property changes (or at least the ones that fire the notification) I "clone" the mclsRecurrence object so it's a new instance with the same properties. Not very efficient, but that's the way it has to work in order for the event to recognize that the value of the cell has changed.
Mike Saltzman said: One way to get around this would be to have your control return a new instance of the Recurrence class any time it gets modified, instead of just altering properties on the same instance. Another option might be to override Equals and GetHasCode on the Recurrence class so that it only return equal when the instance has exactly the same values instead of doing a reference comparison.
One way to get around this would be to have your control return a new instance of the Recurrence class any time it gets modified, instead of just altering properties on the same instance.
Another option might be to override Equals and GetHasCode on the Recurrence class so that it only return equal when the instance has exactly the same values instead of doing a reference comparison.
I have tried to return a new instance of the Recurrence class and no matter what I try I can only get the AfterCellUpdate to fire on the very first time a value gets changed. After that the event doesn't fire again.
When I try the option to Override Equals and GetHashCode nothing happens for me.