PropertyGrid – NumericUpDown Range Editor


OK, that probably sounds like complete rubbish for a title, but I had to get the gist of it out there.

This set of classes that allows a .Net PropertyGrid (Written in C# but should be convertible into other .Net CLR’s) to have a field that is driven by a the NumericUpDown toolbox Form type (Not WPF).

It also allows direct edit, of the field and will then do range validation (and correction) of the value entered.
And, will work with any number that will go into a PropertyGrid, i.e. not limited to the UpDown decimal type.

Here’s an example of how the attributes can be added to an existing PropertyGrid field (in bold):

[

DescriptionAttribute("0 is automatic, use 1 for problem finding scenario’s.\rRange 0 <-> 32"),
DisplayName("Thread Count"), CategoryAttribute("Dokan"
)]
[
TypeConverter(typeof(NumericUpDownTypeConverter))]
[
Editor(typeof(NumericUpDownTypeEditor), typeof(UITypeEditor)), MinMaxAttribute
(0, 32)]
public ushort ThreadCount { get; set; }

This shows the TypeConverter to allow direct editing.
The UITypeEditor to show the NumericUpDown control.
And, the new attribute to set the range MinMaxAttribute

The MinMaxAttribute can also take a step and increment values (They default to 1 if not specified).

The classes are currently here:

http://liquesce.codeplex.com/SourceControl/changeset/view/75980#1725747

 

Credit to the following sources:

http://social.msdn.microsoft.com/Forums/da-DK/netfxbcl/thread/370ce9d3-fc44-4cdc-9c76-dd913c9b572f

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/afcd4dd5-5538-433b-8cac-78c081ee16b6

http://social.msdn.microsoft.com/Forums/en/winforms/thread/b9325e61-767b-43c8-96a2-e0caef2cecad

 

Advertisements

One thought on “PropertyGrid – NumericUpDown Range Editor

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s