منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
كيف امنع كتابة الحروف في DataGridView - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم اسئلة VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=183)
+--- الموضوع : كيف امنع كتابة الحروف في DataGridView (/showthread.php?tid=7457)



كيف امنع كتابة الحروف في DataGridView - عبد الله - 20-12-12

السلام عليكم ورحمة الله وبركاته

وفق الله الجميع لكل خير ، وأعاننا وإياكم على نفع المسلمين ..

إخواني لدي أداة DataGridView وأريد منع الحروف فيها وكذلك بعض الأرقام ، جربت هذه الطريقة ..

كود :
Private Sub DataGridView1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles DataGridView1.KeyPress
        Select Case e.KeyChar
            Case "0", "1", ControlChars.Back
                e.Handled = False
            Case Else
                e.Handled = True
        End Select
    End Sub

ولم تعمل معي الطريقة ، فما الحل في مثل هذه الحالة ...؟


كيف امنع كتابة الحروف في DataGridView - kslawy - 20-12-12

كود :
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing        Dim TextEdit As TextBox = e.Control
        RemoveHandler TextEdit.KeyPress, AddressOf TextBox_KeyPress_Number
        AddHandler TextEdit.KeyPress, AddressOf TextBox_KeyPress_Number
    End Sub


    Public Sub TextBox_KeyPress_Number(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Dim KeyAscii As Short = Asc(e.KeyChar)
        Select Case KeyAscii
            Case 48, 49, 8
                e.Handled = False
            Case Else
                e.Handled = True
        End Select
        ' 48 is KeyAscii for Number 0
        ' 49 is KeyAscii for Number 1
        ' 8 is KeyAscii for Back Key
    End Sub