0

我正在编写代码以确保如果按下翻译按钮,则会出现一个新行,但除字符串文本之外的所有行成员都是可见的。现在我已经编写了代码,但它只会使按钮消失并且所有成员仍然存在可见的。 现在这是初始数据网格视图

这是按下按钮后的视图.. 在此处输入图像描述

现在按钮不可见,但所有其他成员仍然可见。这是我尝试过的代码..

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    bool ce = false;
    bool check = true;
    Column_handling();
    DataGridViewTextBoxCell c = new DataGridViewTextBoxCell();
    if(!(dataGridView1.Rows[e.RowIndex].Selected))
    {
        dataGridView1.Rows[e.RowIndex].Selected = false;
        if (e.ColumnIndex == 10)
        {
            if((Convert.ToInt16(this.dataGridView1.Rows[e.RowIndex].Cells[0].Value) == Convert.ToInt16(this.dataGridView1.Rows[e.RowIndex + 1].Cells[0].Value)) && (Convert.ToInt16(this.dataGridView1.Rows[e.RowIndex].Cells[1].Value) == Convert.ToInt16(this.dataGridView1.Rows[e.RowIndex + 1].Cells[1].Value)))
            {
                ce = true;
            }
            if(!ce)
            {
                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);
                var row = this.dataGridView1.Rows[e.RowIndex + 1];
                DataGridViewColumn column = dataGridView1.Columns[2];
                DataGridViewCell cella = new DataGridViewTextBoxCell();
                cella.Style.BackColor = Color.Wheat;
                column.CellTemplate = cella;
                var cell = new DataGridViewTextBoxCell();
                cell.Value = string.Empty;
                var cell1 = new DataGridViewTextBoxCell();
                cell1.Value = string.Empty;
                var cell2 = new DataGridViewTextBoxCell();
                cell2.Value = string.Empty;
                var cell3 = new DataGridViewTextBoxCell();
                cell3.Value = string.Empty;
                var cell4 = new DataGridViewTextBoxCell();
                cell4.Value = string.Empty;
                var cell5 = new DataGridViewTextBoxCell();
                cell5.Value = string.Empty;
                var cell6 = new DataGridViewTextBoxCell();
                cell6.Value = string.Empty;
                var cell7 = new DataGridViewTextBoxCell();
                cell7.Value = string.Empty;
                var cell8 = new DataGridViewTextBoxCell();
                cell8.Value = string.Empty;
                var cell9 = new DataGridViewTextBoxCell();
                cell9.Value = string.Empty;
                var cell10 = new DataGridViewTextBoxCell();
                cell10.Value = string.Empty;
                row.Cells[10] = cell;//the button column
                row.Cells[0] = cell2;
                row.Cells[1] = cell3;
                row.Cells[3] = cell4;
                row.Cells[4] = cell5;
                row.Cells[5] = cell6;
                row.Cells[6] = cell7;
                row.Cells[7] = cell8;
                row.Cells[8] = cell9;
                row.Cells[9] = cell10;
                cell.ReadOnly = true;
                dataGridView1.ReadOnly = true;
                dataGridView1.Refresh();
            }
            else if (!cao)
            {
                dataGridView1.Rows[e.RowIndex + 1].Visible = true;
                var row = this.dataGridView1.Rows[e.RowIndex + 1];
                var cell = new DataGridViewTextBoxCell();
                cell.Value = string.Empty;
                row.Cells[10] = cell;
                cell.ReadOnly = true;
                dataGridView1.Refresh();
                cao = true;
            }
            else if (ce)
            {
                dataGridView1.Rows[e.RowIndex + 1].Visible = false;
                var row = this.dataGridView1.Rows[e.RowIndex + 1];
                var cell = new DataGridViewTextBoxCell();
                cell.Value = string.Empty;
                row.Cells[10] = cell;
                cell.ReadOnly = true;
                dataGridView1.Refresh();
                cao= false;
            }
        }
    }
}
4

0 回答 0