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.
Hi Jeff,
I ran your sample and expanded the child band and I can see the that row is not tall enough to display the entire RenderingControl. Is that the issue you are seeing?
The grid tries to AutoSize the row and in doing so it will call into the editor for it's Size, which in turn calls into the GetPreferredSize method of the RenderingControl. So what you need to do in order to make the sizing work is to override GetPreferredSize on your ctlRecurrenceWeekly control and return the appropriate size that you want the control to be.How you calculate that size is up to you, and in some cases, you might want to take the font or the contents of the cell into account. But just as a test, I added this code and that worked fine:
Public Overrides Function GetPreferredSize(proposedSize As Size) As Size Return New Size(538, 166) End Function
Of course, you probably don't want to hard-code the numbers here because it vary by system resolution, DPI, font, etc.
As for the updating, that's a little trickier. The way it typically works is that your control uses a value type. So when you set the value on your control, you would send a notification that the property value changed. But in this case, you are not setting the value, you are just setting properties on an reference type object. In other words, the instance of the object doesn't change, only properties ON that object are changing.
Also.. since your sample has only one child row and you are creating a new editor and a new set of controls for each row, it's really hard to tell that the grid is not recognizing the change in the row. The only way to know that is that you can see the RowSelector is not changing to a pencil icon when you change something.
Anyway... editor is looking for a change notification from the EditingControlProperty - in this case "Recurrence". And your control is not sending one.
What you need to do here is to send a PropertyChanged notification for the "Recurrence" property any time one of it's child properties changes. You are already hooking PropertyChanged on the object itself, so you just need to bubble up this notification to the control.
First, implement INotifyPropertyChanged on your control:
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Then send a notification when something changes:
Private Sub Recurrence_PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Me.UpdateUI() 'Dim e2 As PropertyChangedEventArgs = New PropertyChangedEventArgs("Recurrence") 'RaiseEvent PropertyChanged(Me, e2) End Sub
I updated your sample with this code and now when I clicked on a checkbox inside the cell, like Monday, I see the row selector image turn into a pencil, indicating that the row is dirtied.
So that seems to fix both problems you are describing.
In addition, I noticed that you have to click twice for the checkboxes to respond. This is because the first click puts the cell into edit mode and then the second one changes the checkbox. But since your Editing and Rendering controls are the same, you can fix this like so:
containerEditorScheduleType.EnterEditModeMouseBehavior = EnterEditModeMouseBehavior.EnterEditModeAndClick
Finally... there doesn't seem to be any need to create an editor for every cell. Maybe you just did that as an attempted workaround, but it's very inefficient and you are going to end up creating a lot of controls. You'd be much better off just creating the editor and attaching it to the column, rather than the cell.
Hi Mike,
First thank you for the updated sample project. I do have a couple of questions to wrap this up.
The AfterCellUpdate event does not seem to get fired when changing the value only the CellChange event. Is there a reason?
When you mention,
Mike Saltzman said:Finally... there doesn't seem to be any need to create an editor for every cell. Maybe you just did that as an attempted workaround, but it's very inefficient and you are going to end up creating a lot of controls. You'd be much better off just creating the editor and attaching it to the column, rather than the cell.