For example I have 2 items: Item1 is string
and Item2 is int
. How can I set max length for Item1 8 chars and for Item2 5 digits(in c#)?
Asked
Active
Viewed 1,439 times
5

Ria
- 10,237
- 3
- 33
- 60

Ali Ahmadi
- 2,387
- 4
- 31
- 48
-
How about by have the property set throw an exception? – Marc Gravell Sep 23 '12 at 06:47
-
I want just set numbers < 1000 for item2, How can i it ?(When type 4 chars, item2 don't allow for typing this(more than 3 digits)) – Ali Ahmadi Sep 23 '12 at 07:23
-
1PropertyGrid does not support that type of scenario, afaik – Marc Gravell Sep 23 '12 at 07:25
1 Answers
0
To do that, simply use StringLengthAttribute and IntegerValidatorAttribute.
class TestCase
{
[StringLength(8, ErrorMessage = "The TestString value cannot exceed 8 characters.")]
[Required(ErrorMessage="Value Required")]
property string TestString;
[IntegerValidator(MaxValue = 99999)]
property int TestInt;
}

virious
- 571
- 1
- 8
- 27
-
3This doesn't appear to have any effect on how the property grid treats the property. – BlueMonkMN May 05 '14 at 13:26