Q:

Foreach DataGridViewRow procedure

So, after many tryings (and changing the source idea of project) I made some code which works well if one row is selected (i.e. some cells of one single row).
But, I want to repeat the same for multiple rows ( if any cell selected) - except for the first and last row (i.e. rowIndex 0 and newRow). Things become too complicated. Could somebody help?
int r = dgvC.CurrentRow.Index;
var selCells = dgvC.SelectedCells;
var hColumn = (from DataGridViewCell c in selCells;
               orderby c.ColumnIndex descending select c).FirstOrDefault();

List<DataGridViewCell> q = new List<DataGridViewCell> { };
foreach (DataGridViewCell p in dgvC.CurrentRow.Cells)
{
    if (p.ColumnIndex > hColumn.ColumnIndex)
    {
        q.Add(p);
    }
}

foreach (DataGridViewCell v in dgvN.Rows[r].Cells)
{
    if (v.ColumnIndex > 0)
    {
        q.Add(v);
    }
}

List<string> a = new List<string> { };
foreach (DataGridViewCell cell in dgvC.SelectedCells)
{
    a.Add(cell.Value.ToString());
    a.Reverse();
}

List<string> result = (from ignored in Enumerable.Range(0, int.MaxValue)
                       from item in a select item).Take(q.Count).ToList();

for (int i = 0; i < q.Count; i++)
{
    q.ElementAt(i).Value = result.ElementAt(i);
}

A:

I think this code needs a complete rewrite. I'm assuming the following about your intentions, sort of confirmed in the discussion above.
You start with two DGVs, which look like this:
dgvC                         dgvN
+--------------------------+ +--------------------------+ 
|  C1  C2  C3  C4  C5  C6  | |  N1  N2  N3  N4  N5  N6  |
+--------------------------+ +--------------------------+
|  v1  v2  v3  v4  v5  v6  | |  v20 v21 v22 v23 v24 v25 |
|  v7  v8  v9  v10 v11 v12 | |  v26 v27 v28 v29 v30 v31 |
|  v13 v14 v15 v16 v17 v18 | |  v32 v33 v34 v35 v36 v37 |
+--------------------------+ +--------------------------+

If the user selects C2 and C3 of row 2 in dgvC and runs your code, you want it to modify your tables like this:
dgvC                         dgvN
+--------------------------+ +--------------------------+ 
|  C1  C2  C3  C4  C5  C6  | |  N1  N2  N3  N4  N5  N6  |
+--------------------------+ +--------------------------+
|  v1  v2  v3  v4  v5  v6  | |  v20 v21 v22 v23 v24 v25 |
|  v7  v8  v9  v9  v8  v9  | |  v26 v8  v9  v8  v9  v8  |
|  v13 v14 v15 v16 v17 v18 | |  v32 v33 v34 v35 v36 v37 |
+--------------------------+ +--------------------------+

But, if you rectangle-select C2, C3, and C4 in rows 2 and 3, you want it to look like this:
dgvC                         dgvN
+--------------------------+ +--------------------------+ 
|  C1  C2  C3  C4  C5  C6  | |  N1  N2  N3  N4  N5  N6  |
+--------------------------+ +--------------------------+
|  v1  v2  v3  v4  v5  v6  | |  v20 v21 v22 v23 v24 v25 |
|  v7  v8  v9  v10 v10 v9  | |  v26 v8  v10 v9  v8  v10 |
|  v13 v14 v15 v16 v16 v15 | |  v32 v14 v16 v15 v14 v16 |
+--------------------------+ +--------------------------+

Am I correct so far?
If so, I would write the code like this:
int loRow = dgvC.SelectedCells.Cast<DataGridViewCell>().Select(c => c.RowIndex).Min();
int hiRow = dgvC.SelectedCells.Cast<DataGridViewCell>().Select(c => c.RowIndex).Max();

int loCol = dgvC.SelectedCells.Cast<DataGridViewCell>().Select(c => c.ColumnIndex).Min();
int hiCol = dgvC.SelectedCells.Cast<DataGridViewCell>().Select(c => c.ColumnIndex).Max();

for (int i = loRow; i <= hiRow; i++)
{
    // start copying from the rightmost selected cell in the current row
    int curCopyCol = hiCol;

    // now copy to dgvC, starting with hiCol + 1
    for (int j = hiCol + 1; j < dgvC.Columns.Count; j++)
    {
        dgvC.Rows[i].Cells[j].Value = dgvC.Rows[i].Cells[curCopyCol--].Value;

        if (curCopyCol < loCol)
            curCopyCol = hiCol;
    }

    // finally, continue copying in dgvN, starting from the second cell
    for (int j = 1; j < dgvN.Columns.Count; j++)
    {
        dgvN.Rows[i].Cells[j].Value = dgvC.Rows[i].Cells[curCopyCol--].Value;

        if (curCopyCol < loCol)
            curCopyCol = hiCol;
    }
}

This code has been tested in VS2010 targeting .NET 3.5.
Edited to fix and expand on the comments.

