Question

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

Was it helpful?

Solution

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/

OTHER TIPS

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. :)

For client-side you can use JQuery, but if you need a quick solution just use asp.net Validators (Specifically CompareValidator)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top