تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
كيف امنع كتابة الحروف في DataGridView
#1
السلام عليكم ورحمة الله وبركاته

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

إخواني لدي أداة 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

ولم تعمل معي الطريقة ، فما الحل في مثل هذه الحالة ...؟
قال رسول الله صلى الله عليه وسلم ( من قال لا إله إلا الله دخل الجنة ) حديث صحيح.
قال رسول الله صلى الله عليه وسلم ( كلمتان خفيفتان على اللسان ثقيلتان في الميزان حبيبتان للرحمن : سبحان الله وبحمده سبحان الله العظيم ) حديث صحيح.
الرد }}}
تم الشكر بواسطة:
#2
كود :
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
(وَقُل رَّبِّ زِدْنِي عِلْمًا)

الرد }}}
تم الشكر بواسطة:



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم