'程式內加入
Dim NewColumn As New DataGridViewCheckBoxColumn
NewColumn.HeaderText = "選擇"
NewColumn.Name = "chk_resend"
DataGridView1.Columns.Add(NewColumn)
'變更欄位的位置
DataGridView1.Columns("chk_resend").DisplayIndex = 0
'取得datagridview裡的checkbox的改變事件
Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
If DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value = False Then
....程式碼
End If
End Sub
'讓datagridview裡的checkbox能夠即時反應
Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged
If DataGridView1.IsCurrentCellDirty Then
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub