Link to home
Start Free TrialLog in
Avatar of winterhowl
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(FieldNameTypeEditor), typeof(System.Drawing.Design.UITypeEditor))]
        [TypeConverter(typeof(FieldNameConverter))]
        public string FieldName
        {
            get { return m_FieldName; }
            set { m_FieldName = value; }
        }
    }

    public class FieldNameConverter : TypeConverter
    {
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            ArrayList alTest = new ArrayList();

            alTest.Add("one");
            alTest.Add("two");
            alTest.Add("three");

            StandardValuesCollection svc = new StandardValuesCollection(alTest);

            return svc;
        }

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return true;
        }
   }

    public class FieldNameTypeEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.DropDown;
        }
    }
}
ASKER CERTIFIED SOLUTION
Avatar of DarkoLord
DarkoLord
Flag of Slovenia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of winterhowl
winterhowl

ASKER

Without that line, I still don't get a list of values.
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 :)