I am new to C# and am having trouble with getting data to wrap in a DataGridView.
I have placed the code I have below. I am not sure what I am doing wrong or missing.
private void Form_Load(object sender, EventArgs e)
{
this.dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells; // Resizes height changes to all cells for Text to fit
this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True; // Wraps text inside the cells
this.dataGridView1.Columns[4].Width = 300; // Set colmunDescritpion to fixed width
this.dataGridView1.Columns[0].Width = 200; // Set colmunDescritpion to fixed width
int count = 0; // Varialble used to perform count of columns before moving to next row in table.
string line = ""; // Variable used to store data from file.txt
using (StreamReader sr = new StreamReader(@"File Location")) // Reads the data from the file.txt file
{
while (!sr.EndOfStream) // Allows for data in Text file to be separated by comma delimiter
{
line += sr.ReadLine() + ",";
count++;
if (count >= 5) // Adds data to correct rows in table by counting the columns
{
string[] parts = line.Split(',').ToArray();
dataGridView1.Rows.Add(parts[0], parts[1], parts[2], parts[3], parts[4]);
count = 0;
line = "";
}
}
}
}
}
}Thanks in advance for any help with fixing this issue.
Regards,