TypeConverter

M

Martin Venter

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;

}

}

}
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top