문제

I have a Winforms PropertyGrid.

When trying to set value in a variable. I want to throw an error to PropertyGrid as error that appears after putting an invalid value.

enter image description here

There is a way to do this?

도움이 되었습니까?

해결책

You simply throw an exception in the set:

private int someProperty;
public int SomeProperty {
    get { return someProperty; }
    set {
        if((value % 3) != 0) throw new ArgumentOutOfRangeException(
            "the value must be divisible by 3");
        someProperty = value;
    }
}

Produces:

enter image description here

enter image description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top