26-05-13, 10:31 PM
جرب هذا
****
***
**
*
كود :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.Columns(0).ReadOnly = True ' نجعل عمود الترقيم للقراءة فقط
End Sub
Private Sub DataGridView1_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
If e.ColumnIndex = 1 Then ' إذا كان العمل علي عمود الرقم
If Me.DataGridView1.IsCurrentCellDirty Then ' هل يتم العمل علي الخلية
If e.FormattedValue <> String.Empty Then ' قيمة الخلية ليست فارغة
Me.DataGridView1.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1 ' يتم إضافة ترقيم للعمود الأول وذلك عند طريق الاندكس تبع الصف بزيادة واحد
Else
Me.DataGridView1.Rows(e.RowIndex).Cells(0).Value = Nothing ' إذا الخلية فارغة يتم إزالة الترقيم
End If
End If
End If
End Sub****
***
**
*

