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();
}
以上是我的代码。如上所述,它在线上崩溃。我无法想象它为什么会崩溃。任何帮助将不胜感激。