need your help about datagridview
-
hi, My problem is that my boss told me he didn't want to everytime add a new row to datagridview he must provide new values for new row's cell. Actually. in an added row, only one or two cell need changing values, others are unchangeable. He did want to copy an existing row and paste as new row as well as change the needed values without appearing errors I tried to use getClipboardContent() method to manually add values of an existing row to a new row but its not working. I think everybody here could help me solve this by showing me how to copy a gridview row and paste as a new row without errors or suggest me a new way to solve this. Thanks in advance [my code]
string[] str; private void copyToolStripMenuItem_Click(object sender, EventArgs e) { DataObject obj = dataGridView1.GetClipboardContent(); str = obj.GetText(TextDataFormat.CommaSeparatedValue).Substring(1).Split(','); } private void pasteToolStripMenuItem_Click(object sender, EventArgs e) { try { DataGridViewRow dgvRow = dataGridView1.Rows[0]; for (int i = 1; i < str.GetLength(0); i++) dgvRow.Cells[i].Value = str[i]; dataGridView1.Rows.Add(dgvRow); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
It seem to be a solution or an answer.