views:

181

answers:

3

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

A: 

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

o.k.w
A: 

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

Faruz
Client-side validation won't work. The user can simply turn Javascript off in their browser to circumvent the validation. Client-side validation should only be used *to complement* server-side validation as a help for the user. It should not replace it.
John Scipione
That depends on the situation and the purpose of the application. Of course that public applications you should add also a server side validation. But that's much easier to implement...
Faruz
A: 

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/

Rob Fonseca-Ensor
yes am using WinForm.Thanks for the help..
Girish