Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I'm hoping to find a way to prevent symbols in my vb.net windows forms application using a datagridview with the Char.IsSymbol() method, however I'm hoping to still allow the user to input mathmatical operators into the datagridview. Is there a way to prevent all symbols except mathmatical operators? Here is what I have so far, which prevents all symbols, math operators, subscripts and superscripts. However I'm hoping there is a simple way of preventing symbols while allowing math operators. Thanks for any help or suggestions you may offer.

VB
If(columnindex = 0) Then ' checking value for column 1 only
Dim cellString = DataGridView1.Rows(rowindex).Cells(columnindex).value

If Char.IsSymbol(cellString)
MessageBox.Show("Special Characters Not Allowed")
End If
End If
Posted
Updated 3-Feb-14 8:30am
v2
Comments
Sergey Alexandrovich Kryukov 3-Feb-14 15:15pm    
Are you doing a kind of CAS? It does not seem to be a good approach. Here is a hint for you: are you sure you really need to create some input language for symbolic expressions?
—SA

1 solution

There's no way to change the behavior of IsSymbol.

So, you're going to have to write your own method to determine what's acceptable and what's not. Instead of black-listing known characters, use a white-list instead. Accept only the characters you want instead of trying to filter out all the characters you don't.
 
Share this answer
 
Comments
Matt T Heffron 3-Feb-14 17:59pm    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900