主题:[讨论]DataGridViewButtonColumn click事件
我写了如下代码:
DataGridViewButtonColumn Details = new DataGridViewButtonColumn();
Details.Text = "显示Id";
//清除标题
Details.HeaderText = "显示Id";
Details.UseColumnTextForButtonValue = true;
//添加该列
myDataGrid.Columns.Add(Details);Details.Name = "Details";
private void myDataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridView dgv = (DataGridView)sender;
if (dgv.Columns[e.ColumnIndex].Name == "Details") // Details 是你的 ButtonColumn 名称
{
MessageBox.Show(e.RowIndex.ToString());
}
}
可是点击了按钮列之后什么反应也没有,设置断点发现定义的事件跟本没有被调用,怎么回事呀???
DataGridViewButtonColumn Details = new DataGridViewButtonColumn();
Details.Text = "显示Id";
//清除标题
Details.HeaderText = "显示Id";
Details.UseColumnTextForButtonValue = true;
//添加该列
myDataGrid.Columns.Add(Details);Details.Name = "Details";
private void myDataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridView dgv = (DataGridView)sender;
if (dgv.Columns[e.ColumnIndex].Name == "Details") // Details 是你的 ButtonColumn 名称
{
MessageBox.Show(e.RowIndex.ToString());
}
}
可是点击了按钮列之后什么反应也没有,设置断点发现定义的事件跟本没有被调用,怎么回事呀???