Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 6-Feb-13 2:48am
(unknown member)

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



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100