Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

Why my ListView Control is not sorted after I added items to it?

This Listview control (NodeDetail) is selected to sort Ascending in the designer.  I added some items to the list using code below when the form is loaded but the listing is not softed at all.  How can I get it to sort?  Thanks.

                NodeDetail.Items.Add(new ListViewItem(new string[] { "Successful Kerberos Activity Report",
                "Display successful kerberos activity information." }, 9));
                NodeDetail.Items.Add(new ListViewItem(new string[] { "Failed Kerberos Activity Report",
                "Display failed Kerberos Activity information." }, 9));
                NodeDetail.Items.Add(new ListViewItem(new string[] { "All Kerberos Activity Report",
                "Display all Kerberos Activity information." }, 9));
                NodeDetail.Sort();
                NodeDetail.Refresh();
ASKER CERTIFIED SOLUTION
Avatar of gena17
gena17

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lapucca
lapucca

ASKER

I did a search in my project and I fond the code in the designer.cs.  My view is set to "Detail" view.

this.NodeDetail.Sorting = System.Windows.Forms.SortOrder.Ascending;
lapucca

I tried your code in VS and it works ok.
Can you send more code, so we'll be able to check more?
Thanks.
Avatar of lapucca

ASKER

You're right.  I need to add the following in my code then it worked.  Thanks.
this.NodeDetail.Sorting = System.Windows.Forms.SortOrder.Ascending;