[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Custom control dropdown property.  Values not showing up.

Posted on 2007-07-29
4
Medium Priority
?
448 Views
Last Modified: 2008-03-03
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;
        }
    }
}
0
Comment
Question by:winterhowl
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 500 total points
ID: 19589117
You don't need this line (it will automatically switch to dropdown if you return a list of values):

[Editor(typeof(FieldNameTypeEditor), typeof(System.Drawing.Design.UITypeEditor))]
0
 

Author Comment

by:winterhowl
ID: 19589299
Without that line, I still don't get a list of values.
0
 

Author Comment

by:winterhowl
ID: 19589311
Nevermind.  I was wrong in my last statement.  You were absolutely right, and Thank You.  :)
0
 

Expert Comment

by:untold242
ID: 19694102
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 :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2
Suggested Courses
Course of the Month18 days, 20 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question