我有一个DataGridView
,最后一列是DataGridViewButtonCell
(用于编辑)。
我想做以下事情:
当鼠标在一行上时,如果将被隐藏,将显示“编辑”按钮,如果将被隐藏。
我尝试了许多方法,但无法理解。
答案 0 :(得分:0)
您可以将DataGridViewButtonCell更改为DataGridViewTextBoxCell。
以下是一个示例。
private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{
for (int index = 0; index < dataGridView1.Rows.Count; index++)
{
DataGridViewRow dr = dataGridView1.Rows[index];
if (index == dataGridView1.CurrentCell.RowIndex)
{
DataGridViewTextBoxCell txtCell = new DataGridViewTextBoxCell();
dr.Cells[0] = txtCell;
}
else
{
DataGridViewButtonCell buttonCell = new DataGridViewButtonCell();
dr.Cells[0] = buttonCell;
}
}
}
}