开发者

How do I keep PropertyGrid from bringing up the invalid value message box multiple times?

开发者 https://www.devze.com 2023-03-27 04:11 出处:网络
In my propertygrid, I support an Hour value that converts a string like \"8 AM\" to an Hour object. There are only 24 possible values for them, but I don\'t want to restrict the user to using the drop

In my propertygrid, I support an Hour value that converts a string like "8 AM" to an Hour object. There are only 24 possible values for them, but I don't want to restrict the user to using the drop down.

So the custom HourConverter : StringConverter implements GetStandardValues, but forces GetStandardValuesExclusive to false. I want the user to be able to type in the hour if they want to, but get an error if a mistake was made (ConvertFrom throws a FormatException).

Here is the problem: if the user enters an invalid value, the "Property Value Invalid" message box pops up as expected. But now, if I try to get the correct value through the drop down, the alert box comes up once when the drop down is triggered, and another 2-3 times after I've chosen a valid value from the list. It looks like when the drop down is created, ConvertFrom is called on all the string values in the list including the invalid one sitting in the text box.

What ends up happening is that if the value in the box is invalid, the user can't correct it at all by looking at the list, b开发者_如何学编程ecause that just pops up more messages no matter what is chosen, and nothing changes. How can I prevent this? Do I just have to set GetStandardValuesExclusive to return true?

0

精彩评论

暂无评论...
验证码 换一张
取 消