Using custom TypeEditor does not notify parent property

Discussion in 'ASP .Net Building Controls' started by Rob Mayo, Jul 17, 2003.

  1. Rob Mayo

    Rob Mayo Guest

    I have built a custom UITypeEditor for picking web colors for my server control. It's pretty much the same typeeditor as the one you get when you select bgcolor of a document in an aspx page. Since I couldn't figure out which one it was, I decided to build one myself.

    It seems to work fine, but the properties I've set to use the editor have the NotifyParentProperty attribute set to True. If I type in the property grid, it notifies the parent property and redraws the control on the page. If I use the editor, it doesn't notify. It waits for me to update some other property before redrawing.

    Is there some code I need to implement to get it to notify that I've changed a property?

    Imports System.Windows.Forms
    Imports System.ComponentModel
    Imports System.Drawing.Design
    Imports System.Windows.Forms.Design

    Public Class WebColorEditor
    Inherits UITypeEditor

    Private service As IWindowsFormsEditorService

    Public Overloads Overrides Function EditValue( _
    ByVal context As ITypeDescriptorContext, _
    ByVal provider As IServiceProvider, _
    ByVal value As Object) As Object

    If (Not context Is Nothing And _
    Not context.Instance Is Nothing And _
    Not provider Is Nothing) Then
    service = CType( _
    provider.GetService(GetType(IWindowsFormsEditorService)), _
    IWindowsFormsEditorService)

    If (Not service Is Nothing) Then
    Dim Instance As New ClientSideCalendar.DropStyle()
    Instance = CType(context.Instance, ClientSideCalendar.DropStyle)
    Dim nColor As System.Drawing.Color
    Dim strColorName As String

    If context.PropertyDescriptor.Name.ToString.ToLower = "color" Then
    strColorName = Instance.Color
    ElseIf context.PropertyDescriptor.Name.ToString.ToLower = "backgroundcolor" Then
    strColorName = Instance.BackgroundColor
    End If

    Dim nForm As New WebColorEditorForm()

    If (nForm.Execute(nColor, strColorName)) Then
    If context.PropertyDescriptor.Name.ToString.ToLower = "color" Then
    Instance.Color = strColorName
    ElseIf context.PropertyDescriptor.Name.ToString.ToLower = "backgroundcolor" Then
    Instance.BackgroundColor = strColorName
    End If

    End If

    nForm = Nothing
    Return strColorName

    End If
    End If

    Return value
    End Function




    Public Overloads Overrides Function GetEditStyle( _
    ByVal context As ITypeDescriptorContext) _
    As UITypeEditorEditStyle

    If (Not context Is Nothing And Not context.Instance Is Nothing) Then
    Return UITypeEditorEditStyle.Modal
    End If

    Return MyBase.GetEditStyle(context)

    End Function

    End Class
     
    Rob Mayo, Jul 17, 2003
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.