合并两个相同的列值时需要间距

时间:2016-01-14 11:19:12

标签: c#

我需要合并2个列值 - 它运行良好。但是,2个值之间没有空格。以下是我的代码。请让我知道我必须纠正的地方:

DataGridViewTextBoxColumn dgvctime = new DataGridViewTextBoxColumn();
        dgvctime.Name = cmbColumn1.Text;
        dgvctime.HeaderText = cmbColumn1.Text;
        dataGridView1.Columns.Add(dgvctime);

        //dataGridView1.Rows.Add(dgvctime);

        int rowadded = 0;

        for (int RowCount = 1; RowCount <= strfile.Length - 1; RowCount++)
        {
            if (strfile[RowCount].ToString() != "")
            {
                if (RowCount != 0)
                {
                    //dataGridView1.Rows.Add();
                    string[] column = strfile[RowCount].Split('þ');
                    rowadded = 0;
                    for (int i = 1; i < column.Length - 1; i++)
                    {
                        //dataGridView1.Rows.Add();
                        if ((cmbColumn1.SelectedIndex == ((i - 1) / 2)) || (cmbColumn2.SelectedIndex == ((i - 1) / 2)))
                        {
                            if (rowadded == 0)
                            {
                                rowadded = 1;
                                dataGridView1.Rows.Add();
                            }
                            if (column[i].ToString() != "\u0014")
                            {
                                //dataGridView1.Rows[RowCount - 1].Cells[cmbColumn1.Text].Value += column[i].ToString();
                                dataGridView1.Rows[RowCount - 1].Cells[cmbColumn1.Text].Value += column[i].ToString();
                   `         }
                        }
                    }

                }
            }

2 个答案:

答案 0 :(得分:0)

只需添加简短的更新

dataGridView1.Rows[RowCount - 1].Cells[cmbColumn1.Text].Value += " " + column[i].ToString();

答案 1 :(得分:0)

更改此行...

dataGridView1.Rows[RowCount - 1].Cells[cmbColumn1.Text].Value += " " + column[i].ToString();