1

これは私のデータグリッドビューのビューです..

ここに画像の説明を入力

これは翻訳ボタンで、クリックすると横に新しい行が表示され、その行で新しいボタンも初期化されます。 翻訳ボタンを押すと

今私が欲しいのは、翻訳ボタンがクリックされた場合、表示される新しい行に翻訳ボタンが含まれていないことです..ボタンを動的に初期化しました..これが私のコードです。

   private void button()
    {
        var buttonCol = new DataGridViewButtonColumn();
        buttonCol.Name = "ButtonColumnName";
        buttonCol.HeaderText = "Header";
        buttonCol.Text = "Translate";
        buttonCol.Name = "Edit";
        buttonCol.Width = 30;
        buttonCol.UseColumnTextForButtonValue = true;
        dataGridView1.Columns.Add(buttonCol);
    }

ボタンがクリックされたときのイベントです。

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
       // button();
        Column_handling();
        if (e.ColumnIndex == 10)
        {
            DataRow dt = datarows.NewRow();
            dt[0] = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
            dt[1] = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
            dt[2] = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
            dt[3] = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
            dt[4] = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
            dt[5] = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();
            dt[6] = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();
            dt[7] = this.dataGridView1.CurrentRow.Cells[7].Value.ToString();
            dt[8] = this.dataGridView1.CurrentRow.Cells[8].Value.ToString();
            dt[9] = this.dataGridView1.CurrentRow.Cells[9].Value.ToString();
            datarows.Rows.InsertAt(dt, e.RowIndex+1);
            dataGridView1.Refresh();
        }    

何か案は?

4

3 に答える 3

2

セルタイプを に変更する必要がありますTextBox

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
        Column_handling();
        if (e.ColumnIndex == 10)
        {
            DataRow dt = datarows.NewRow();
            //fillign vlaues
            datarows.Rows.InsertAt(dt, e.RowIndex + 1);

            var row = this.dataGridView1.Rows[e.RowIndex + 1];
            var cell = new DataGridViewTextBoxCell();
            cell.Value = string.Empty;

            row.Cells["ButtonColumnName"] = cell;

            cell.ReadOnly = true;

            dataGridView1.Refresh();
        }
}

ReadOnlyユーザーが何も入力できないようにセルを作成しました。

于 2013-07-10T06:54:59.807 に答える