Hey guys, I'm getting an error when I want t add a file to my dataGridView that I can't add any data because it is databound. I've been working around this but still gives me the same error. heres the snippet of the code:
If anyone can help that would be awesome.
Thanks.
Code:
private void btnOpenLog_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
{
String sLine = "";
try
{
System.IO.StreamReader FileStream = new System.IO.StreamReader(openFileDialog1.FileName);
sLine = FileStream.ReadLine();
string[] s = sLine.Split(';');
for (int i = 0; i <= s.Count() - 1; i++)
{
DataGridViewColumn colHold = new DataGridViewTextBoxColumn();
colHold.Name = "col" + System.Convert.ToString(i);
colHold.HeaderText = s[i].ToString();
dataGridView1.Columns.Add(colHold);
}
sLine = FileStream.ReadLine();
while (sLine != null)
{
dataGridView1.Rows.Add();
for (int i = 0; i <= s.Count() - 1; i++)
{
s = sLine.Split('|');
dataGridView1.Rows[dTable.Rows.Count - 1].Cells[i].Value = s[i].ToString();
}
sLine = FileStream.ReadLine();
}
FileStream.Close();
}
catch (Exception err)
{
System.Windows.Forms.MessageBox.Show("Error: " + err.Message, "Program Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Thanks.
Comment