. Net control development-type converter

Source: Internet
Author: User
Type converter that provides the standard value list to the "properties" Window

For attributes such as province, we usually put them in a drop-down box to facilitate user input. A province contains cities, and we usually list some of them. If the data does not meet user requirements, you can also input the data by yourself and use the type converter.

To achieve this effect, you need to override the following method. We add an attribute.Name of a favorite game
Because the attribute is of the string type, it can be derived directly from stringconverter.

Example 3Public class gameconverter: stringconverter

{
// Returns whether this object supports the standard value set that can be selected from the list.
Public override bool getstandardvaluessupported (
Itypedescriptorcontext context)
{
Return true;
}
// Return to the Collection class in the drop-down box
Public override standardvaluescollection
Getstandardvalues (itypedescriptorcontext context)
{
Return new standardvaluescollection (New String [] {"legend ",
"World of Warcraft ",
"Dragon and underground city "});
}
// Whether the set of standard values is an exclusive list
// The default value is flase. If it is true, the list value cannot be modified.
Public override bool getstandardvaluesexclusive (
Itypedescriptorcontext context)
{
Return false;
}
}

And associate it with related attributes.

[Typeconverter (typeof (gameconverter)]
[Description ("favorite games")]
Public String Game
{
Get
{
Return game;
}
Set
{
Game = value;
}
}

Okay. Let's take a look at the effect. For example, you can select the value in the drop-down box or manually enter it. It is similar to the enumeration type, but the enumeration type cannot be modified by yourself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.