winterhowl
asked on
Custom control dropdown property. Values not showing up.
I'm trying to create a custom property within a custom control that limits the developer's value choices to a dropdown list. I have the property showing as a dropdown, but the values are not showing up.
What am I doing wrong here?
using System;
using System.Collections.Generic ;
using System.ComponentModel;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Drawing.Design;
using System.Text;
using System.Windows.Forms;
namespace CSharp_HelloWorld
{
public partial class CustomControl1 : TextBox
{
private string m_FieldName = string.Empty;
public CustomControl1()
{
InitializeComponent();
}
[Editor(typeof(FieldNameTy peEditor), typeof(System.Drawing.Desi gn.UITypeE ditor))]
[TypeConverter(typeof(Fiel dNameConve rter))]
public string FieldName
{
get { return m_FieldName; }
set { m_FieldName = value; }
}
}
public class FieldNameConverter : TypeConverter
{
public override StandardValuesCollection GetStandardValues(ITypeDes criptorCon text context)
{
ArrayList alTest = new ArrayList();
alTest.Add("one");
alTest.Add("two");
alTest.Add("three");
StandardValuesCollection svc = new StandardValuesCollection(a lTest);
return svc;
}
public override bool GetStandardValuesSupported (ITypeDesc riptorCont ext context)
{
return true;
}
public override bool GetStandardValuesExclusive (ITypeDesc riptorCont ext context)
{
return true;
}
}
public class FieldNameTypeEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescript orContext context)
{
return UITypeEditorEditStyle.Drop Down;
}
}
}
What am I doing wrong here?
using System;
using System.Collections.Generic
using System.ComponentModel;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Drawing.Design;
using System.Text;
using System.Windows.Forms;
namespace CSharp_HelloWorld
{
public partial class CustomControl1 : TextBox
{
private string m_FieldName = string.Empty;
public CustomControl1()
{
InitializeComponent();
}
[Editor(typeof(FieldNameTy
[TypeConverter(typeof(Fiel
public string FieldName
{
get { return m_FieldName; }
set { m_FieldName = value; }
}
}
public class FieldNameConverter : TypeConverter
{
public override StandardValuesCollection GetStandardValues(ITypeDes
{
ArrayList alTest = new ArrayList();
alTest.Add("one");
alTest.Add("two");
alTest.Add("three");
StandardValuesCollection svc = new StandardValuesCollection(a
return svc;
}
public override bool GetStandardValuesSupported
{
return true;
}
public override bool GetStandardValuesExclusive
{
return true;
}
}
public class FieldNameTypeEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescript
{
return UITypeEditorEditStyle.Drop
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nevermind. I was wrong in my last statement. You were absolutely right, and Thank You. :)
Thanx this is indeed working, however! When you try this by hitting F5 in VS.NET 2005 the option greys out and you get a NullReferenceException error. When you try by loading your custom control in another project it works just fine, so don't go wasting houres and houres on finding the solution :)
ASKER