context is null in my TypeConverter.ConvertFrom() method

Discussion in 'ASP .Net Web Controls' started by lucianoluke@bol.com.br, May 5, 2006.

  1. Guest

    Hi all,

    I am trying to have a collection serialized to a property of the parent
    control in HTML.

    The collection items are controls found in the page. When the designer
    is being loaded, My TypeConverter.ConvertFrom is called. The problem is
    that ITypeDescriptorContext context is null.

    I tryied creating a ControlDesigner and overriding
    DesignTimeHtmlRequiresLoadComplete to always return true; No good. The
    ConvertFrom is called BEFORE my ControlDesigner constructor's is even
    called.

    Is there any spell that I can cast to solve this problem?

    my property attributes are:
    Code:
    -----------------------------------------
    [Description("The tabs displayed on this control")]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [PersistenceMode(PersistenceMode.Attribute)]
    [TypeConverter(typeof(TabCollectionTypeConverter))]
    [Editor(typeof(TabCollectionUITypeEditor), typeof(UITypeEditor))]
    public TabCollection TabPanels
    {
    get
    {
    object tabs = this.ViewState["TabPanels"] as TabCollection;
    if (tabs != null)
    {
    return (TabCollection) tabs;
    }
    return new TabCollection();
    }
    set
    {
    this.ViewState["TabPanels"] = value;
    }
    }
    
    ------------------------------------------------------
    TabCollectionTypeConverter
    public override object ConvertFrom(ITypeDescriptorContext context,
    CultureInfo culture, object value)
    {
    TabCollection tc = new TabCollection();
    
    if (context != null && value is string)
    {
    string[] v = ((string)value).Split(new char[] {','});
    foreach (string s in v)
    {
    ComponentCollection components = context.Container.Components;
    foreach (IComponent component in components)
    {
    if (!(component is Control))
    {
    continue;
    }
    
    HPTabPanel ctrl = (HPTabPanel)component;
    if ((ctrl.ClientID != null) && (ctrl.ClientID.Length != 0) &&
    ctrl.ClientID == s)
    {
    tc.Add(ctrl);
    }
    }
    }
    }
    
    return tc;
    }
    -------------------------------------  UITypeEditor
    public override object EditValue(ITypeDescriptorContext context,
    IServiceProvider provider, object value)
    {
    if (provider != null)
    {
    IWindowsFormsEditorService editorService =
    (IWindowsFormsEditorService)
    provider.GetService(typeof(IWindowsFormsEditorService));
    if (editorService == null)
    {
    return value;
    }
    
    // get forms editor service
    IWindowsFormsEditorService wfes =
    provider.GetService(typeof(IWindowsFormsEditorService)) as
    IWindowsFormsEditorService;
    
    // create our form
    TabCollectionEditorForm form = new TabCollectionEditorForm(context,
    value as TabCollection);
    
    // show our form
    wfes.ShowDialog(form);
    
    // Force designer update
    context.OnComponentChanged();
    
    // return updated value
    return form.Tabs;
    }
    
    // just in case
    return base.EditValue(context, provider, value);
    }
    ------------------------------
    
    Notice that I dont want to have InnerProperties and the like. I want my
    control data string stored in a property.

    Thanks for any input that may help.

    Luciano Bargmann
     
    , May 5, 2006
    #1
    1. Advertising

  2. Luciano Bargmann, May 5, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian
    Replies:
    1
    Views:
    475
    Gary Varga
    Jul 18, 2003
  2. Replies:
    0
    Views:
    428
  3. Replies:
    5
    Views:
    27,284
    Mike Schilling
    Mar 29, 2006
  4. Maxus
    Replies:
    0
    Views:
    472
    Maxus
    Apr 12, 2007
  5. Replies:
    1
    Views:
    513
    Chris A.
    May 17, 2006
Loading...

Share This Page