Results 1 to 6 of 6

Thread: Validating Data Entry with a datagrid

  1. #1

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

    Validating Data Entry with a datagrid

    I have loaded data into the grid and the next thing that I want to be able to do is:

    1. Validate user entry that is make sure they haven't placed alphas where I only wanted numbers. Anyone got any suggestions?

    2. Limit the number of characters users can put in the grid. Again suggestions appreciated.

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Hmm...I haven't used the data grid extensively, but does it expose properties on a per column basis? I've used alot of grids that allow this, but as I stated, I really havent used the data grid.

  3. #3

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    found out how to do 2, you can play with this sorta stuff with
    DataGridTextBoxColumns

    eg
    txtCol.TextBox.MaxLength= x

    but still need to work out how to validate user entry?

  4. #4

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Originally posted by Lethal
    Hmm...I haven't used the data grid extensively, but does it expose properties on a per column basis? I've used alot of grids that allow this, but as I stated, I really havent used the data grid.
    Yeah the new datagrid is pretty cool in that it allows you to directly bind multiple tables to a datagrid at once and the user can just select which table they want to see. The only problem that I am finding is that as soon as you want to start mucking around with the defaults, you gotta learn the object model beneath the control and in this case there are a couple such as DataGridTableStyle and GridColumnStyles that you have to get comfy with. So I am flying in the dark a little here, but I guess it is kinda fun, like having your girlfriend think it's funny to wax your leg, "no sweetie my leg is killing, don't go any higher and do my arms"

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    How bout something like this?

    Code:
        Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
            Dim iDigit = System.Convert.ToInt32(e.KeyChar)
            Dim bSpace = (iDigit = 32)
            Dim bBackSpace = (iDigit = 8)
    
            If Not System.Char.IsDigit(e.KeyChar) Then
                If (Not bSpace And Not bBackSpace) Then
                    e.Handled = True
                End If
            End If
        End Sub
    Last edited by Lethal; Oct 27th, 2002 at 07:14 PM.

  6. #6

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Tried this but nothing was printed in the debug window

    Code:
    Private Sub DataGrid1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DataGrid1.KeyPress
            Debug.WriteLine(Me.DataGrid1.CurrentCell.RowNumber)
            Debug.WriteLine(e.KeyChar)
            ' check for your active column to restrict input
            'If Not System.Char.IsDigit(e.KeyChar) Then
            '    If Not System.Char.IsControl(e.KeyChar) And Not e.KeyChar = CType(e.KeyChar, Char) Then
            '        e.Handled = True
            '    End If
            'End If
    
        End Sub

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