16-09-18, 01:32 PM
إذا كانت الأسطر كثيرة استخدم DataGridView بثلاث أعمدة TextBox وعمود رابع Button
وهذه كود الاستخدام إن شاء الله تكون واضحة
كود :
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
sender.EndEdit()
If e.ColumnIndex = 3 Then
Dim btn As DataGridViewButtonCell = sender.Item(e.ColumnIndex, e.RowIndex)
If btn.FormattedValue = "Add" Then
Add(sender.CurrentRow)
'btn.Style.NullValue = "Update"
Else
Update(sender.CurrentRow)
'btn.Style.NullValue = "Add"
End If
End If
End Sub
Private Sub Add(row As DataGridViewRow)
row.Cells(3).Style.NullValue = "Update"
Dim txt1 As String = TryCast(row.Cells(0).Value, String)
Dim txt2 As String = TryCast(row.Cells(1).Value, String)
Dim txt3 As String = TryCast(row.Cells(2).Value, String)
MsgBox("Add Row: " & row.Index & vbNewLine & _
"txt1: " & txt1 & vbNewLine & _
"txt2: " & txt2 & vbNewLine & _
"txt3: " & txt3)
End Sub
Private Sub Update(row As DataGridViewRow)
row.Cells(3).Style.NullValue = "Add"
Dim txt1 As String = TryCast(row.Cells(0).Value, String)
Dim txt2 As String = TryCast(row.Cells(1).Value, String)
Dim txt3 As String = TryCast(row.Cells(2).Value, String)
MsgBox("Update Row: " & row.Index & vbNewLine & _
"txt1: " & txt1 & vbNewLine & _
"txt2: " & txt2 & vbNewLine & _
"txt3: " & txt3)
End Sub