Click here to Skip to main content
15,909,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a requirement like in FORM1, i have a button called MERGE. After clicking on it, another form opens and i have selected the columns from 2 dropdowns to merge. It's merging the 2 column values and displaying in datagrid (in form2).

But, i want one column from form1 to display along with merged columns. Can anyone help me on this? Below is my merge button code :

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DATApplication
{
    public partial class frmMerge : Form
    {
        public frmMerge(String[] datfile1)//DataGridView dgv)
        {
            InitializeComponent();
            strfile = datfile1;

        }

        String[] strfile;

        private void btnMerge_Click(object sender, EventArgs e)
        {
            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();
                                }
                            }
                        }

                    }
                }
            }



        }

        private void button1_Click(object sender, EventArgs e)
        {
            ClsSaveDat Savdat = new ClsSaveDat();
            Savdat.SaveDat(dataGridView1);
        }

    }
}


What I have tried:

I tried to add the column i want in the form2. It's displaying the column but with empty values. I want the values also to display. Can you please help me achieving this?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900