0

我有一个按钮,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";
        }
    }
4

1 回答 1

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";

        }
    }
于 2013-01-21T12:32:07.040 回答