Click here to Skip to main content
12,957,398 members (57,669 online)
Rate this:
 
Please Sign up or sign in to vote.
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 6-Feb-13 1:48am
arnavs15

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,994
CHill60 3,550
Maciej Los 3,312
ppolymorphe 2,170
Jochen Arndt 1,973


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2017
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