如何在单元格中获取/设置DataGridViewButtonColumn的值?

时间:2017-08-12 17:31:52

标签: c# c#-4.0 datagridview

我尝试在Datagridview中为DataGridViewButtonColumn单元格设置值。

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{

if (dgv.Columns[e.ColumnIndex].Name.Equals("id")) {
   e.Value = 14;
}            
}

然后我尝试在点击事件后获得价值:

 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
    if (dataGridView1.CurrentCell.ColumnIndex.Equals(1) && e.RowIndex != -1)
    {
      // GET HERE 
    }
}

那么,如何在事件e.Value = 14中获得价值dataGridView1_CellClick

1 个答案:

答案 0 :(得分:1)

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    var dg = (DataGridView)sender;
    dg[e.ColumnIndex, e.RowIndex].Value = 123;
}