![](/img/trans.png)
[英]Delete a DataTable row, source of selected DataGridView row, on button click
[英]Delete row from DataGridView via button on the row
如何通过行上的按钮删除DataGridView行?
屏幕截图: http : //i.imgur.com/8342MKT.png
当用户单击一行上的“삭제”按钮时,我要删除该行。
我尝试了这个:
For Each row As DataGridViewRow In DataGridView1.SelectedRows
DataGridView1.Rows.Remove(row)
Next
但是,尽管这适用于DataGridView外部的按钮,但不适用于DataGridView中的按钮。
如何使用DataGridView中的按钮使它起作用?
Option Strict On
Option Explicit On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i As Integer = 0 To 5
DataGridView1.Rows.Add(i.ToString, i.ToString, i.ToString, "삭제")
Next
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.ColumnIndex = 3 Then
DataGridView1.Rows.RemoveAt(e.RowIndex)
End If
End Sub
End Class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.