منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : تحديد نقطة واحدة dot في حقل ال datagridview
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام عليكم ورحمة الله وبركاته
وكا عام وانتم بالف خير
ممكن المساعدة في تحديد نقطة واحدة (فاصلة عشرية ) في كتابة الرقم في حقل ال datagridview ...فقد قمت بذلك في textbox كما يلي :
Private Sub textbox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles textbox1.KeyPress
        ' حدث كتابة أرقام فقط في الحقل
      
        If Asc(e.KeyChar) <> 8 Then
            If Asc(e.KeyChar) < 46 Or Asc(e.KeyChar) > 57 Then
                e.Handled = True
            End If
        End If
        If textbox1.Text.Contains(".") Then
            If e.KeyChar = "." Then
                e.Handled = True
            End If
        End If
    End Sub
كيف يمكن ذلك في حق ال datagridview
وبارك الله بكم
كود :
Private Sub DataGridView1_GotFocus(sender As Object, e As EventArgs) Handles DataGridView1.GotFocus
    RemoveHandler CType(sender, DataGridView).EditingControlShowing, AddressOf DataGridView1_EditingControlShowing
    AddHandler CType(sender, DataGridView).EditingControlShowing, AddressOf DataGridView1_EditingControlShowing
End Sub
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs)
    If sender.CurrentCell.ColumnIndex = 0 Then ' <<<< ColumnIndex
        Dim TB = CType(e.Control, TextBox)
        RemoveHandler TB.KeyPress, AddressOf DataGridView1_KeyPress
        AddHandler TB.KeyPress, AddressOf DataGridView1_KeyPress
    End If
End Sub
Private Sub DataGridView1_KeyPress(sender As Object, e As KeyPressEventArgs)
    ' حدث كتابة أرقام فقط في الحقل

    If Asc(e.KeyChar) <> 8 Then
        If Asc(e.KeyChar) < 46 Or Asc(e.KeyChar) > 57 Then
            e.Handled = True
        End If
    End If
    If sender.Text.Contains(".") Then
        If e.KeyChar = "." Then
            e.Handled = True
        End If
    End If
End Sub
السلام عليكم ورحمة الله وبركاته
أشكر لكم مروركم... وكل عام وانتم بالف خير ...
واجهة مشكلة في كتابة الكود ...
Private Sub DGVewItems_KeyPress(sender As Object, e As KeyPressEventArgs) Handles DGVewItems.KeyPress
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 46 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
If sender.Text.Contains(".") Then
If e.KeyChar = "." Then
e.Handled = True
End If
End If
End Sub
Private Sub DGVewItems_GotFocus(sender As Object, e As EventArgs) Handles DGVewItems.GotFocus
RemoveHandler sender.EditingControlShowing, AddressOf DGVewItems_EditingControlShowing
AddHandler sender.EditingControlShowing, AddressOf DGVewItems_EditingControlShowing
End Sub
Private Sub DGVewItems_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs)
If sender.CurrentCell.ColumnIndex = 13 Then ' <<<< ColumnIndex
Dim TB = CType(e.Control, TextBox)
RemoveHandler TB.KeyPress, AddressOf DGVewItems_KeyPress
AddHandler TB.KeyPress, AddressOf DGVewItems_KeyPress
End If
End Sub
أن كل من sender.EditingControlShowing و sender.EditingControlShowing يشار لها بالخطأ

class.system.object
supports all classes in the .net framework class hierarchy and providers low -level services to derived classes. this ultimate base class of classes in the .net framework it is the root of the type hierarchy . to browse the .net framework source code for this type , see the references source. "EditingControlShowing" is not an event of "Object"
جرب هذا الكود :

كود :
   Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing

       RemoveHandler e.Control.KeyPress, AddressOf EditingControl_KeyPress
           AddHandler e.Control.KeyPress, AddressOf EditingControl_KeyPress


   End Sub
   Sub EditingControl_KeyPress(sender As Object, e As KeyPressEventArgs)
       Dim editingControl As Control = sender

       If DataGridView1.CurrentCell.ColumnIndex = 1 Then
           If (Not Char.IsControl(e.KeyChar)) Then
               If Not Regex.IsMatch(editingControl.Text + e.KeyChar, "^[-+]?\d*\.?\d*$") Then
                   e.Handled = True
               End If
           End If
       End If
   End Sub

https://stackoverflow.com/questions/1551...user-input
السلام عليكم ورحمة الله وبركاته
أشكر لكم مروركم...
ولكن لم تتحق النتيجة ...
(04-08-20, 02:51 PM)Mohammed Nafa كتب : [ -> ]السلام عليكم ورحمة الله وبركاته
أشكر لكم مروركم...
ولكن لم تتحق النتيجة ...

ارفق البرنامج نعدل عليه اذا امكن
كود :
Private Sub DGVewItems_KeyPress(sender As Object, e As KeyPressEventArgs) Handles DGVewItems.KeyPress
    If Asc(e.KeyChar) <> 8 Then
        If Asc(e.KeyChar) < 46 Or Asc(e.KeyChar) > 57 Then
            e.Handled = True
        End If
    End If
    If sender.Text.Contains(".") Then
        If e.KeyChar = "." Then
            e.Handled = True
        End If
    End If
End Sub
Private Sub DGVewItems_GotFocus(sender As Object, e As EventArgs) Handles DGVewItems.GotFocus
    RemoveHandler CType(sender, DataGridView).EditingControlShowing, AddressOf DGVewItems_EditingControlShowing
    AddHandler CType(sender, DataGridView).EditingControlShowing, AddressOf DGVewItems_EditingControlShowing
End Sub
Private Sub DGVewItems_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs)
    If sender.CurrentCell.ColumnIndex = 13 Then ' <<<< ColumnIndex
        Dim TB = CType(e.Control, TextBox)
        RemoveHandler TB.KeyPress, AddressOf DGVewItems_KeyPress
        AddHandler TB.KeyPress, AddressOf DGVewItems_KeyPress
    End If
End Sub
(04-08-20, 02:19 PM)Anas Mahmoud كتب : [ -> ]جرب هذا الكود :

كود :
   Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing

       RemoveHandler e.Control.KeyPress, AddressOf EditingControl_KeyPress
           AddHandler e.Control.KeyPress, AddressOf EditingControl_KeyPress


   End Sub
   Sub EditingControl_KeyPress(sender As Object, e As KeyPressEventArgs)
       Dim editingControl As Control = sender

       If DataGridView1.CurrentCell.ColumnIndex = 13 Then '<<<<<<<< ColumnIndex
           If (Not Char.IsControl(e.KeyChar)) Then
               If Not Regex.IsMatch(editingControl.Text + e.KeyChar, "^[-+]?\d*\.?\d*$") Then
                   e.Handled = True
               End If
           End If
       End If
   End Sub

https://stackoverflow.com/questions/1551...user-input
الكود يعمل بدون اي مشاكل عندي

[attachment=25382]

السطر ده تتحكم منه في اي عمود نحتاج ان نتحكم في مدخلات المستخدم

كود :
If DataGridView1.CurrentCell.ColumnIndex = 2 Then

انا في المثال ده عملته العمود اللي index بتاعه = 2
السلام عليكم ورحمة الله وبركاته
أشكر لكم مروركم...
وبارك الله بكم ....
الكود يعمل بشكل ممتاز ....