VB.NET
'ボタン作成
Dim column As New DataGridViewButtonColumn()
column.Name = "btncol"
column.UseColumnTextForButtonValue = True
column.Text = "表示"
dgv1.Columns.Add(column)
C#//ボタン作成
DataGridViewButtonColumn column = new DataGridViewButtonColumn();
column.Name = "btncol";
column.UseColumnTextForButtonValue = true;
column.Text = "表示";
dgv1.Columns.Add(column);
DataGridViewセルボタンのクリックイベントを捕獲する方法VB.NET
Private Sub dgv1_CellContentClick(ByVal sender As Object, _
ByVal e As DataGridViewCellEventArgs) _
Handles dgv1.CellContentClick
Dim dgv As DataGridView = CType(sender, DataGridView)
If dgv.Columns(e.ColumnIndex).Name = "Button" Then
MessageBox.Show((e.RowIndex.ToString() + "行クリック"))
End If
End Sub
C#private void dgv1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
DataGridView dgv = (DataGridView)sender;
if (dgv.Columns[e.ColumnIndex].Name == "Button")
{
MessageBox.Show(e.RowIndex.ToString() + "行クリック");
}
}