C# DataGridView on WinForm - index was out of range

  • Thread starter Thread starter Ihandler MSDN
  • Start date Start date
I

Ihandler MSDN

Guest
I have a tab delimited file and want to import into DataGridView

However, I got an error due to "Index was out of range", I dig into the code and unable to find any problems.

Could somebody provide me some help here?

private void LoadTabData(string[] lines)
{
int i = 0;
int j = 0;

foreach (string line in lines)
{
// Split the line
string[] array = line.Split(new Char[] { '\t' });


if (i == 0)
{
this.FormatGrid(array);
}
else
{
grid.Rows.Add();
for (j = 0; j < array.Length; j++)
{
grid[j, i].Value = array.GetValue(j); // <--- ERROR right here (index was out of range)
}
}

i++;
}
}

Continue reading...
 
Back
Top