[2008] DataGridViewTextBoxColumn - only allow certain characters
Hello,
Is there a way of only permitting certain characters in a DataGridViewTextBoxColumn?
I want one particular column to only accept any of the following:
0123456789<>
... and maybe a backspace.
Re: [2008] DataGridViewTextBoxColumn - only allow certain characters
Yes, you can handle the KeyPress event (to prevent the user from keying in an invalid character) and/or the TextChanged event (to prevent the user from pasting in an invalid value) of the DataGridViewTextBoxEditingControl. Search the forum for the term "DataGridViewTextBoxEditingControl" and you should find some examples.
Re: [2008] DataGridViewTextBoxColumn - only allow certain characters
Hmmm. DataGridViewTextBoxEditingControl isn't coming up with anything on this forum.
However, thanks for the pointer.
Re: [2008] DataGridViewTextBoxColumn - only allow certain characters
Handle the EditingControlShowing event of the grid. If the current column is the one you're interested in then EditingControl is a reference to the aforementioned DataGridViewTextBoxEditingControl and you can use AddHandler to attach the appropriate event handlers. Just note that you will need to use RemoveHandler to remove them again though, or you will likely end up with issues.
Note that a DataGridViewTextBoxEditingControl is just an inherited TextBox that implements IDataGridViewEditingControl, as are all controls that get embedded in a DataGridView.
Re: [2008] DataGridViewTextBoxColumn - only allow certain characters
Quote:
Originally Posted by penguin5000
Hmmm. DataGridViewTextBoxEditingControl isn't coming up with anything on this forum.
However, thanks for the pointer.
Oopsss... I gave you a bad search term. Sorry. Try searching for "EditingControlShowing" and this is the returned list:
http://www.vbforums.com/search.php?searchid=1783749