Jayanta Mukherjee

Jayanta Mukherjee

  • 1.5k
  • 120
  • 38.7k

Why multi column data showing in a single column in listview c#

Dec 26 2021 2:42 PM

I'm trying to export data from a .xlsx file to a Listview control where the date of the "Due Date" column falls between today's date and the next 10 days from today and below is my code (I'm using EPPlus library for excel file stuff):

using (ExcelPackage package = new ExcelPackage(new FileInfo(filename), false))
{
    ExcelWorksheet mainSheet = package.Workbook.Worksheets.First();
    listView1.Columns.Add("OrderCode");
    listView1.Columns.Add("Invoice");
    listView1.Columns.Add("Items");
    listView1.Columns.Add("NetAmount");
    listView1.Columns.Add("Due Date");
    for (int row = 2; row <= 100; row++)
    { 
        for (int col = 1; col < 6; col++)
        {
 	        if (DateTime.Parse(mainSheet.Cells[row, 5].Text) >= DateTime.Today && DateTime.Parse(mainSheet.Cells[row, 5].Text) <= DateTime.Today.AddDays(10))
            {
                listView1.Items.Add(mainSheet.Cells[row, col].Text);
            }
        }
    }
}

But all the data are clumping in the first column of the Listview, even though I've set View property to Details. Also, the data filtering by dates falling in the above mentioned range is not working as intended.

How to fix this?


Answers (1)