Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private string[,] LoadCsv(string filename)
- {
- string whole_file = File.ReadAllText(filename);
- whole_file = whole_file.Replace('n', 'r');
- string[] lines = whole_file.Split(new char[] { 'r' },
- StringSplitOptions.RemoveEmptyEntries);
- int num_rows = lines.Length;
- int num_cols = lines[0].Split(',').Length;
- string[,] values = new string[num_rows, num_cols];
- for (int r = 0; r < num_rows; r++)
- {
- string[] line_r = lines[r].Split(',');
- for (int c = 0; c < num_cols; c++)
- {
- values[r, c] = line_r[c];
- }
- }
- return values;
- string[,] values = LoadCsv(textBox2.Text);
- int num_rows = values.GetUpperBound(0) + 1;
- int num_cols = values.GetUpperBound(1) + 1;
- dgvValues.Columns.Clear();
- for (int c = 0; c < num_cols; c++)
- dgvValues.Columns.Add(values[0, c], values[0, c]);
- for (int r = 1; r < num_rows; r++)
- {
- dgvValues.Rows.Add();
- for (int c = 0; c < num_cols; c++)
- {
- dgvValues.Rows[r - 1].Cells[c].Value = values[r, c];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement