This is what I wrote, but does not work for me. I need if my array starts at 5, I would like to delete the second row that already exists in gridview, and would like to add it after adding a specific row
if (line.StartsWith("5")) { int oldRow = 1; dataGridView1.Rows.Add(itemarray(dataGridView1.Rows[1])); dataGridView1.Rows.RemoveAt(oldRow); dataGridView1.Rows.Add("BatchHeader", line); m_flag = true; StringBuilder sb = new StringBuilder(); objfileentry.createFileEntry(Append.FileName, out sb); if (m_flag) dataGridView1.Rows.Add("FileControl", sb.ToString()); line = string.Empty; }
This function is from you
private object[] itemarray(DataGridViewRow Row) { int a = Row.DataGridView.ColumnCount - 1; object[] mOut = new object[a + 1]; for (int x = 0; x <= a; x++) { mOut[x] = Row.Cells[x].Value; } return mOut; }
source share