private void importFile()
{
TextFieldParser parser = new TextFieldParser(@"E:\\test.csv");
parser.TextFieldType = FieldType.Delimited;
parser.SetDelimiters(",");
dataGridView1.Columns[0].Name = "URL";
dataGridView1.Columns[1].Name = "Valid";
while (!parser.EndOfData)
{
//Processing row
string[] fields = parser.ReadFields();
foreach (string field in fields)
{
//TODO: Process field
// Crashes on line below with message
// Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
row.Cells[0].Value = field;
row.Cells[1].Value = "";
dataGridView1.Rows.Add(row);
}
}
parser.Close();
}
上記は私のコードです。上記のように、ラインでクラッシュします。なぜクラッシュするのか想像できません。任意の支援をいただければ幸いです。