تقييم الموضوع :
  • 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
الرد }}}
تم الشكر بواسطة:
#2
PHP كود :
Private Sub txtEdit_Keypress(ByVal sender As ObjectByVal e As System.Windows.Forms.KeyPressEventArgs)
    If e.KeyChar "." And sender.Text.Contains("."Then
        e
.Handled True
        
Exit Sub
    End 
If

    'هنا نسمح بكتابة ارقام فقط وحقول معينة بها فاصلة 
    Console.WriteLine("KeyPress " & e.KeyChar.ToString())
    '
Test for numeric value or backspace in first column
    
If DataGridViewX1.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

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

    If DataGridViewX1.CurrentCell.ColumnIndex Or DataGridViewX1.CurrentCell.ColumnIndex 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 
الرد }}}
#3
اشكرك من كل قلبي  
بصراحة هذا المطلوب  
وتم حل المشكلة شكرا لك
الرد }}}
تم الشكر بواسطة:



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


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