I created the listview as followed:
Then I have a CSV file with 5 columns. I read the file to populate the rows:
The problem is the column header is not aligned with the data in the listviewitem record. In fact, the columns in listviewitem records is shifted to the right by one position.
Is there anything wrong with my code or it is the nature of CSV file?
Thanks
Code:
ListView lvContent = new ListView();
//Add the column header
lvContent.Columns.Add("Col1");
lvContent.Columns.Add("Col2");
lvContent.Columns.Add("Col3");
lvContent.Columns.Add("Col4");
lvContent.Columns.Add("Col5");
Code:
char[] delim = new char[] {','};
System.IO.StreamReader reader = new System.IO.StreamReader(fileName);
string line;
while ((line = reader.ReadLine()) != null)
{
String[] arr = line.Split(delim);
lvi = new ListViewItem();
for (int i = 0; i < arr.Length; i++) // arr.Length is always 5
{
lvi.SubItems.Add(arr[i]);
}
this.lvContent.Items.Add(lvi);
}
Is there anything wrong with my code or it is the nature of CSV file?
Thanks
Comment