How to set length for PropertyGrid objects in C #?

For example, I have 2 elements: Item1 is string , and Item2 is int . How to set maximum length for Item1 8 characters and for Item2 5 digits (in C #)?

+4
source share
1 answer

To do this, 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; } 
0
source

Source: https://habr.com/ru/post/1435720/


All Articles