Home All Groups Group Topic Archive Search About

context is null in my TypeConverter.ConvertFrom() method

Author
5 May 2006 12:56 PM
lucianoluke
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);
}
------------------------------
[/code]

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

Author
5 May 2006 1:11 PM
Luciano Bargmann
Sorry, I posted this on thi wrong forum. I re-posted it on building
controls, so, PLEASE POST REPLIES THERE :)

Here is the link, and sorry for any inconvenience :P
http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet.buildingcontrols/browse_thread/thread/87e3cd283fbc017d/7d704a7cf357742c?hl=en#7d704a7cf357742c