Results 1 to 7 of 7

Thread: [RESOLVED] control datagridview input characters

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    [RESOLVED] control datagridview input characters

    I have a datagridview (dgvSalesOrderLines ) that has 5 columns. The types are:
    decimal | character | character | decimal | decimal

    I am trying to get it so if the user adds a new row that for columns 0, 3 and 4 that only numeric / decimal data is allowed. The following works the first column but after that nothing works.

    Looking for any help on this.
    Thanks.


    Code:
    Private Sub dgvSalesOrderLines_EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvSalesOrderLines.EditingControlShowing
            Dim iCurCol As Integer = dgvSalesOrderLines.CurrentCell.ColumnIndex
            Select Case iCurCol
                Case 0, 3, 4
                    'only allow numerics
                    If TypeOf e.Control Is TextBox Then
                        Dim tb As TextBox = TryCast(e.Control, TextBox)
                        AddHandler tb.KeyPress, AddressOf dgv_KeyPress
                    End If
                Case Else
                    
            End Select
        End Sub
    
        Private Sub dgv_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
            If Not (Char.IsNumber(e.KeyChar)) Then
                e.Handled = True
            End If
        End Sub
    Last edited by lleemon; Oct 5th, 2012 at 06:47 AM. Reason: resolved

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