简体   繁体   English

范围内的c#datagridview值类型

[英]c# datagridview valuetype with range

hi in c# i can do the following... 嗨,我在C#中可以执行以下操作...

 dataGridView1.Columns["Column2"].ValueType = typeof(double);

is it possible also to provide the range for those double values entered on that column rows... for example i want user to enter only values between 0.0-100.0...? 是否也可以提供在该列行上输入的那些双精度值的范围...例如,我希望用户仅输入0.0-100.0之间的值...? thanks a lot! 非常感谢!

You can't do that by setting a property, but you can handle the CellValidating event and do the validation yourself. 您无法通过设置属性来执行此操作,但是可以处理CellValidating事件并自行进行验证。

You can then set the ErrorText property to an appropriate error message at the corresponding cell or row. 然后,可以在相应的单元格或行上将ErrorText属性设置为适当的错误消息。 You'll then have to set the ErrorText property to an empty string on the CellValidated event. 然后,您必须在CellValidated事件上将ErrorText属性设置为空字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM