|
-
Jul 18th, 2008, 07:17 AM
#1
Thread Starter
Addicted Member
[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.
-
Jul 18th, 2008, 07:53 AM
#2
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.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 18th, 2008, 08:32 AM
#3
Thread Starter
Addicted Member
Re: [2008] DataGridViewTextBoxColumn - only allow certain characters
Hmmm. DataGridViewTextBoxEditingControl isn't coming up with anything on this forum.
However, thanks for the pointer.
-
Jul 18th, 2008, 08:37 AM
#4
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.
-
Jul 18th, 2008, 08:40 AM
#5
Re: [2008] DataGridViewTextBoxColumn - only allow certain characters
 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
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|