Have you tried to define columns?
int[] colsToPrint = new int[]{1, 3, 5, 7, 9};
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (int i in colsToPrint)
{
}
}
[
EDIT]
Accordingly to the solution#2 (added to the question)...
Imagine, you've got one-dimensional array and you want to "convert" it into multi-dimensional array.
Take a look at below example and read all coments carefully.
string inputfile = @"D:\inputgrd.txt";
string outputfile = @"D:\outputgrd.txt";
string[] items = File.ReadAllLines(inputfile);
int j = items.Length;
int cc = 4;
int rr = j % cc;
int rc = (int)(j / cc) + (rr==0 ? 0 : 1);
string[,] a = new string[rc,cc];
for(int i = 0; i < j; i++)
{
int r = (int)i / 4;
int c = (int)i % 4;
a[r,c] = items[i];
}
StringBuilder sb = new StringBuilder();
for(int r = 0; r< rc; r++)
{
string s = $"{a[r,0]} {a[r,1]} {a[r,2]} {a[r,3]}";
Console.WriteLine(s);
sb.AppendLine(s);
}
File.WriteAllText(outputfile, sb.ToString());
Note: It's just an example. You have to change it to your needs.