Click here to Skip to main content
15,889,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i am binding a class to a propertygrid.
Now i will manipulate the propertygrid via attributes.

sample:

class PDFSettings
{
[Range(1,100)]
[DefaultValue(85)]
public int PDFJPEGQUALITY { get; set; }
}


The DefaultValue-Attribute works.

But the Range-Attribute doesen´t work, if I input a non valid value (-1) into my propertygrid nothing happends.

what make i wrong?


Br,

Benny
Posted
Comments
BillWoodruff 20-Apr-15 5:19am    
Are you using the System.ComponentModel.DataAnnotations namespace ? What makes you think the PropertyGrid "knows" anything about your custom Attribute ? Show the code for your Attribute(s).
BoySetsFire 20-Apr-15 6:50am    
Hi Bill!

Thx for your answer!!!


This is my code :)


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using System.Configuration;

namespace PropertyGrid1
{
public partial class Form1 : Form
{

private void Form1_Load(object sender, EventArgs e)
{
PDFSettings settings = new PDFSettings();
propertyGrid1.SelectedObject = settings;
}
}

class PDFSettings
{
[Range(1,100)]
[DefaultValue(85)]
public int PDFJPEGQUALITY { get; set; }
}
BillWoodruff 20-Apr-15 8:18am    
Please add tags to your original post that indicate whether this is an ASP.NET or ASP.MVC project. If this is ASP: what PropertyGrid are you using: the one on CodePlex which is an extension of the CodeProject article by Leppie ?


Please add your code and comments to your original post, and use the CodeProject editor to format the code properly.

Please note that I have not had any experience using the System.ComponentModel.DataAnnotations namespace , or working with an ASP.NET application. I do have experience using custom Attributes and the Property Grid in WinForms however.

I repeat my question: why do you think the PropertyGrid control should use/respond-to your custom Attribute in any way ?

I note that you do not show your code for the custom Attribute as I suggested. You also show no use of the MetaDataType Attribute.

And you don't show code that indicates you are subscribing to any of the Property Grid's events.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900