Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I am working on a windows application and I have a datatable that is having some data. While I am adding the data to the list view in a form its only adding one column value not all column values. Please help me.

Code:
DataTable dt = new DataTable();
            dt = myService.GetLeaveDetails();
            
             lvLeaveDetails.Columns.Clear();
             lvLeaveDetails.Items.Clear();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                lvLeaveDetails.Columns.Add("Column " + i.ToString());
            }

            foreach (DataRow row in dt.Rows)
            {
                string[] subitems = new string[dt.Rows.Count];

                object[] o = row.ItemArray;
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    subitems[i] = o[i].ToString();
                }
                ListViewItem item = new ListViewItem(subitems);
                lvLeaveDetails.Items.Add(item);
            }
            lvLeaveDetails.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);


Thanks
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900