I have an excel sheet with the following:
So, what I am trying to achi
I know it's some years later, but I was looking for a solution for this problem and found BASA's modification of Latheesan's code. It only worked partially, so modifying it, I would like to add this solution for future browsers:
private void Paste(DataGridView d)
{
DataObject o = (DataObject)Clipboard.GetDataObject();
if (o.GetDataPresent(DataFormats.StringFormat))
{
string[] pastedRows = Regex.Split(o.GetData(DataFormats.StringFormat).ToString().TrimEnd("\r\n".ToCharArray()), "\r");
int j = 0;
try { j = d.CurrentRow.Index; } catch { }
foreach (string pastedRow in pastedRows)
{
DataGridViewRow r = new DataGridViewRow();
r.CreateCells(d, pastedRow.Split(new char[] { '\t' }));
d.Rows.Insert(j, r);
j++;
}
}
}