السلام عليكم ورحمة الله وبركاتة
كيف يتم كتابة ارقام فقط داخل عمود في الداتا جريد الخاصة بالفجوال بيسك دت نت 2005
انا عملت سيرش وجبت ميثال واشتغل معايا بس علي جميع الخلايا انا عايز الخلية الاولي فقط
دة الكود بالشرح
ماذا لو أردت أن تجبر المستخدم على ادخال أرقام فقط فى الخلايا
ورب مصائب قوم عند قوم منافع
وتبقى فى يدك وتقسم لغيرك
هذا فعلاً هو الحل
فى حدث
EditingControlShowing
1 - سننشأ عنصر من نوع TextBox
2- ثم نساويه بعنصر الخلية
3- ثم نرسل لك مقبض ( Handle ) لحدث Keypress
لنتحكم فى نوع البيانات المدخلة
حدث EditingControlShowing لعنصر DataGridView
Private Sub DataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlSho wingEventArgs) Handles DataGridView.EditingControlShowing
Dim TextEdit As TextBox = e.Control
RemoveHandler TextEdit.KeyPress, AddressOf TextBox_KeyPress_Number
AddHandler TextEdit.KeyPress, AddressOf TextBox_KeyPress_Number
End Sub
حدث KeyPress لكتابة أرقام فقط للعنصر المرسل منه المقبض ( Handle )
Public Sub TextBox_KeyPress_Number(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
Dim KeyAscii As Short = Asc(e.KeyChar)
If KeyAscii = 8 Then KeyAscii = 8 : Exit Sub
If KeyAscii <= 47 Or KeyAscii > 57 Then KeyAscii = 0
If KeyAscii = 0 Then
e.Handled = True
End If
End Sub
عايز حد يساوي التيكست الجديد بالخلية رقم 0 في الداتا جريد
وشكرا جزيلا