Hi Michael,
I performed a test based on your code snippet and did see the same thing as
you did. When I press Ctrl-Shift-V, a new row is added to the DataGridView
control and the new row is blank.
The DataGridViewRow Collection.AddC opy method adds a new row based on the
row at the specified index. But it doesn't means the new row will copy the
values of the row positioned at the specified index. Instead, it means the
InheritedStyle property of the new row has the same values as the
InheiritedStyle of the row positioned at the specified index. That's to
say, the new row has the same DataGridViewCel lStyle as the specified row
does.
If you change the DefaultCellStyl e property of a row and then add a new row
based on this row by calling the DataGridViewRow Collection.AddC opy method,
you will see the new row has the same DataGridViewCel lStyle as this row.
The following is a sample code to change the DefaultCellStyl e property of a
row.
this.dataGridVi ew1.Rows[0].DefaultCellSty le.BackColor = Color.Azure;
You could add the above line of code in your application to have a test.
To copy the values of the specified row to the new row, you should do it
manually. The following is a sample.
void dataGridView1_K eyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.Shift && e.KeyCode == Keys.V)
{
int selectedRowInde x =
this.dataGridVi ew1.SelectedCel ls[0].RowIndex;
int i = this.dataGridVi ew1.Rows.AddCop y(selectedRowIn dex);
// copy the values of the row positioned at
selectedRowInde x to the new row
this.dataGridVi ew1.Rows[i].Cells[0].Value =
this.dataGridVi ew1.Rows[selectedRowInde x].Cells[0].Value;
this.dataGridVi ew1.Rows[i].Cells[1].Value =
this.dataGridVi ew1.Rows[selectedRowInde x].Cells[1].Value;
.....
}
}
Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.