限制 Datagridview 单元格中的字符
我有一个整数列。 当我编辑此单元格时,我只需要输入数字而不是字符。 我没有使用 datagridviewTextboxColumn。它是一个单元格。 它不应该允许输入字符,就像我们给 Char.IsDigit 来限制字符的 textbox_keyPress 事件一样。
我如何在 C# 中执行此操作?
谢谢
I have a column which is of integer.
when i edit this cell,i need to enter only numbers but not characters.
Am not using datagridviewTextboxColumn.It is a cell.
It should not allow typing characters just like a textbox_keyPress event where we give Char.IsDigit to restrict characters.
How do i do this in C# ?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您询问 C# winforms,那么您只需要构建自己的 DatagridViewColumn 类。 Microsoft 有一个示例演示如何执行此操作:http://msdn.microsoft。 com/en-us/library/ms180996.aspx - 幸运的是,他们恰好展示了如何构建屏蔽文本框!
您可能还需要注意: http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/d0029092-f1ff-4e54-9e01-8fb189c7474c/
If you're asking about C# winforms, then you just need to build your own DatagridViewColumn class. Microsoft have a sample showing how to do this: http://msdn.microsoft.com/en-us/library/ms180996.aspx - luckily for you, they happen to be showing how to build a masked text box!
You might also need to take note of: http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/d0029092-f1ff-4e54-9e01-8fb189c7474c/
服务器端检查很简单。对于客户端,我推荐 JQuery Masked Input 插件。看看这个:http://digitalbush.com/projects/masked-input-plugin/< /a>
不过,您必须以编程方式附加事件。
PS:这是我第三次(我认为)推荐这个解决方案。 :)
Server-side checking is straightforward. For client-side, I would recommend JQuery Masked Input plug-in. Check this out: http://digitalbush.com/projects/masked-input-plugin/
You'll have to attach the event programmatically though.
PS: This is the 3rd time (I think) I've recommended this solution. :)
对于客户端,您可以使用 JQuery,但如果您需要快速解决方案,只需使用 asp.net 验证器(特别是 CompareValidator)
For client-side you can use JQuery, but if you need a quick solution just use asp.net Validators (Specifically CompareValidator)