private void CopyRowAdd(string data, int idx)
{
try
{
DataTable tblData = (DataTable)dataGridView1.DataSource;
DataRow newRow = tblData.NewRow();
string[] rawRowData = data.Split(new char[] { '\r', '\x09' });
for (int i = 0; i < rawRowData.Length; i++)
{
if (i >= tblData.Columns.Count) break;
else
{
newRow[i] = rawRowData[i];
}
}
tblData.Rows.Add(newRow);
dataGridView1.DataSource = tblData;
}
catch (Exception x)
{
System.Console.WriteLine(x.Message);
}
}
private void DataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.C)
{
grvXYMappingInfo.CopyToClipboard();
}
else //
if ( e.Control&&e.KeyCode == Keys.V)
{
try
{
string[] selectedRow = ClipboardData.Split('\n');
string[] addRow = new string[selectedRow.Length-1];
System.Array.Copy(selectedRow, 1, addRow, 0, selectedRow.Length - 1);
if (addRow.Length < 1) return;
int rowidx = 1;
foreach (string row in addRow)
{
CopyRowAdd(row, rowidx);
rowidx++;
}
MessageBox.Show("success");
}
catch (Exception x)
{
System.Console.WriteLine(x.Message);
}
}
}I'm pasting it from Excel to Gridview, but the data isn't working properly.I want to paste data from any cell. Colum number =11