我在datagridview
中有一个按钮,其文字为Start
,所以当我单击时,文本现在应为Stop
,当我再次点击时文字应该是开始。
所以我编写了代码,但它对我不起作用
private void dgvCampaign_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is Button)
{
Button btn = e.Control as Button;
if(btn.Text=="Start")
btn.Text = "Stop";
else
btn.Text = "Start";
}
}
答案 0 :(得分:0)
尝试使用CellContentClick event
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2)
{
if (dataGridView2[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString().Length > 0)
{
if (dataGridView2[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString() == "Start")
{
dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Stop";
}
else
{
dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Start";
}
}
else
dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Start";
}
}