Results 1 to 5 of 5

Thread: [2008] DataGridViewTextBoxColumn - only allow certain characters

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    [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.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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 -

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2008] DataGridViewTextBoxColumn - only allow certain characters

    Hmmm. DataGridViewTextBoxEditingControl isn't coming up with anything on this forum.
    However, thanks for the pointer.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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
    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
  •  



Click Here to Expand Forum to Full Width