TypeConverter

Discussion in 'ASP .Net Building Controls' started by Martin Venter, Nov 8, 2004.

  1. Hi Everyone,

    I have a custom dropdownlist control with a LoadItemsFrom property.
    I created a TypeConverter for this property that displays a list of controls
    of the same type in the property designer.
    This all works great but I would like to exclude the control from the list
    that is being inspected.

    Hope someone can shed some light on this.
    Below is the code of my TypeConverter.

    Regards,
    Martin
    #region ... using ...

    using System;

    using System.Collections;

    using System.ComponentModel;

    using System.Web.UI;

    #endregion

    namespace Unison.Galactrix.Web.UI.WebControls

    {

    /// <summary>

    /// Summary description for AuxiliaryCodesDropDownListConverter.

    /// </summary>

    public class AuxiliaryCodesDropDownListConverter : StringConverter

    {

    public AuxiliaryCodesDropDownListConverter()

    {

    }

    /// <summary>

    /// Gets the list of controls in the container.

    /// </summary>

    /// <param name="container">The <see cref="IContainer"/> to search in for
    controls.</param>

    /// <returns>An array of <see cref="Control"/> ID <see
    cref="String"/>.</returns>

    protected virtual Object[] GetControls( IContainer container )

    {

    ArrayList standardValues = new ArrayList();

    foreach( IComponent component in container.Components )

    {

    Control control = component as Control;

    if ((control != null) && (control is AuxiliaryCodesDropDownList))

    {

    standardValues.Add(String.Copy(control.ID));

    }

    }

    standardValues.Sort();

    return standardValues.ToArray();

    }

    /// <summary>

    /// Overrides <see cref="TypeConverter.GetStandardValues"/>.

    /// </summary>

    /// <returns>Returns an array of <see cref="Control"/> ID <see
    cref="String"/>.</returns>

    public override System.ComponentModel.TypeConverter.StandardValuesCollection
    GetStandardValues(System.ComponentModel.ITypeDescriptorContext context)

    {

    if (context == null || context.Container == null)

    {

    return null;

    }

    object[] standardValues = this.GetControls(context.Container);

    if (standardValues != null)

    {

    return new StandardValuesCollection(standardValues);

    }

    return null;

    }

    /// <summary>

    /// Overrides <see cref="TypeConverter.GetStandardValuesSupported"/>.

    /// </summary>

    /// <returns>Returns true.</returns>

    public override bool
    GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext
    context)

    {

    return true;

    }

    /// <summary>

    /// Overrides <see cref="TypeConverter.GetStandardValuesExclusive"/>.

    /// </summary>

    /// <returns>Returns false.</returns>

    public override bool
    GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext
    context)

    {

    return false;

    }

    }

    }
     
    Martin Venter, Nov 8, 2004
    #1
    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:
    469
    Gary Varga
    Jul 18, 2003
  2. Replies:
    0
    Views:
    418
  3. Harshdeep Mehta
    Replies:
    1
    Views:
    2,092
    Teemu Keiski
    Jul 8, 2004
  4. Sky Sigal
    Replies:
    1
    Views:
    492
    Sky Sigal
    Jul 14, 2004
  5. Replies:
    2
    Views:
    1,745
Loading...

Share This Page