private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "Desktop"; openFileDialog1.Filter = "dat files (*.DAT)|*.DAT|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { FileName = openFileDialog1.FileName; string text = System.IO.File.ReadAllText(FileName); datfile = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); //Added on 2015-12-02 maxRec = datfile.Length - 1; PageCount = maxRec / pageSize; LoadPage(MyFOrmat); //char c = (char)20; #region Before Paging Concept //dataGridView1.Rows.Clear(); //dataGridView1.Columns.Clear(); //string text = System.IO.File.ReadAllText(openFileDialog1.FileName); //String[] datfile = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); //int rowindex = 0; //for (int RowCount = 0; RowCount <= datfile.Length - 1; RowCount++) //{ // if (datfile[RowCount].ToString() != "") // { // if (RowCount == 0) // { // string[] column = datfile[RowCount].Trim('þ').Split('\u0014'); // for (int i = 0; i <= column.Length - 1; i++) // { // // if (column[i].ToString() != '\u0014')//0x00B6\\ // if (column[i].ToString() != "" && column[i].ToString() != "\u0014")//¶ ¶ ¶ // { // //string columnT = column[i].ToString().Trim('þ'); // DataGridViewTextBoxColumn dgvtxtcountry = new DataGridViewTextBoxColumn(); // dgvtxtcountry.HeaderText = column[i].ToString().Trim('þ'); // dgvtxtcountry.Name = column[i].ToString().Trim('þ'); // dataGridView1.Columns.Add(dgvtxtcountry); // cmbList.Add(column[i].Trim('þ')); // } // // i++; // } // } // if (RowCount != 0) // { // dataGridView1.Rows.Add(); // //string[] column = datfile[RowCount].Trim('þ').Split('þ'); // string[] column = datfile[RowCount].Trim('þ').Split('\u0014'); // int index = 0; // for (int i = 0; i <= column.Length - 1; i++) // { // if (column[i].ToString() != "" && column[i].ToString() != "\u0014") // //if (column[i].ToString() != "" && column[i].ToString() != "¶") // { // dataGridView1.Rows[rowindex].Cells[index].Value = column[i].Trim('þ'); // index += 1; // } // } // rowindex += 1; // } // } //} #endregion } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } CODE FOR MERGING TWO COLUMNS: <pre lang="C#">private void btnMerge_Click(object sender, EventArgs e) { frmMerge fs = new frmMerge(dataGridView1); fs.cmbColumn1.DataSource = cmbList; for (int i = 0; i <= cmbList.Count - 1; i++) { fs.cmbColumn2.Items.Add(cmbList[i]); } fs.ShowDialog(); } Thanks in advance.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)