I am working on a C # application that contains many DataGridViews that are empty. The user must fill them with copied / pasted data from excel. I do the following:
int i = 0; string s = Clipboard.GetText(); // Separate lines string[] lines = Regex.Split(s, "\r\n"); foreach (string line in lines) { // Separate each cell string[] cells = line.Split('\t'); foreach (string cell in cells) { // If we selected as many cells as copied if (dataGridView.SelectedCells.Count == (lines.Length-1)*(cells.Length)) { dataGridView.SelectedCells[i].Value = cell; i++; } } }
The problem is that if I copy something like this (on excel):
1 2 3 4 5 6
My datagridview will look like this:
6 4 2 5 3 1
I really don't know what to do to fix this ... Thanks in advance
Blowi
source share