Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
110
UltraControlContainerEditor and Custom Control
posted

Hello,

I am having trouble trying to get UltraControlContainerEditor and my custom control to work properly. I have a couple of issues.

  1. My custom control does not seem to display properly in the child band row where it is supposed to display. I even tried to change the row height in InitializeRow event for the band. I know I am probably missing something.
  2. I cannot seem to get the custom control to update the grid at all. The UltraControlContainerEditor doesn't seem to talk back to the grid when one of the controls in the custom control gets updated.
I have tried to copy the ControlContainerEditorVB project, but it looks like I am missing something.

I have included a small sample project.

TestControlContainer.zip
Parents
  • 469350
    Verified Answer
    Offline posted

    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.

    TestControlContainer.zip
Reply Children