تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
نرجع مرة ثانية , الاداة datagrideview ممنوع تكتب حروف بس في مشكلة
#1
استعملت الكود التالي لمع الاداة من كتابة حروف والمشكلة اريده فقط عند تكرار المستخدم لكتابة الفاصلة العشرية  (.) ان يرفض البرنامج تكرارها في نفس الحقل  

مرفق الكود 


 Private Sub DataGridViewX1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridViewX1.EditingControlShowing
        'منع كتابة حروف
        Dim txtEdit As TextBox = e.Control
        'remove any existing handler
        RemoveHandler txtEdit.KeyPress, AddressOf txtEdit_Keypress
        AddHandler txtEdit.KeyPress, AddressOf txtEdit_Keypress
      

    End Sub
  
    Private Sub txtEdit_Keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        'هنا نسمح بكتابة ارقام فقط وحقول معينة بها فاصلة 
        Console.WriteLine("KeyPress " & e.KeyChar.ToString())
        'Test for numeric value or backspace in first column
        If DataGridView1.CurrentCell.ColumnIndex = 0 Then
            If IsNumeric(e.KeyChar.ToString()) _
            Or e.KeyChar = ChrW(Keys.Back) Then _
        '    Or e.KeyChar = "." Then
                Console.WriteLine("KeyPress number")
                e.Handled = False 'if numeric display 
            Else
                Console.WriteLine("Enter Numbers Only")
                e.Handled = True  'if non numeric don't display
            End If
        End If

        '***********************************************************

        If DataGridViewX1.CurrentCell.ColumnIndex = 2 Or DataGridViewX1.CurrentCell.ColumnIndex = 3 Or DataGridViewX1.CurrentCell.ColumnIndex = 4 Then

            '  If DataGridView1.CurrentCell.ColumnIndex = 0 Then
            If IsNumeric(e.KeyChar.ToString()) _
            Or e.KeyChar = ChrW(Keys.Back) _
            Or e.KeyChar = "." Then
                Console.WriteLine("KeyPress number")
                e.Handled = False 'if numeric display 
            Else
                Console.WriteLine("Enter Numbers Only")
                e.Handled = True  'if non numeric don't display
            End If
        End If

        '*-*-********************************************************

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


الردود في هذا الموضوع
نرجع مرة ثانية , الاداة datagrideview ممنوع تكتب حروف بس في مشكلة - بواسطة nooralcown - 04-02-18, 11:24 PM


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


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