troubleshooting Question

Custom control dropdown property. Values not showing up.

Avatar of winterhowl
winterhowl asked on
C#
4 Comments1 Solution492 ViewsLast Modified:
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;
        }
    }
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros