Solved

c# ListView sorting problem

Posted on 2009-07-14
8
434 Views
Last Modified: 2013-12-17
I have a ListView which I can sort by clicking the columns. This works just fine. But I have a method which deletes a listview item and adds it again. After this the item is at the bottom and not at the same position as befor. I want it where it was. I tried it with lsvListView.Sort(); but its allways at the bottom..


I sort the columns with the ListViewColumnSorter class from Microsoft..
0
Comment
Question by:socom1985
  • 5
  • 3
8 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24846931
>. This works just fine.
can you show it?

for the reference:
http://support.microsoft.com/kb/319401
0
 
LVL 1

Author Comment

by:socom1985
ID: 24846969
I'm sure I'm not getting something..
I have it like in the link for the columns clicks and it works..
but when I add a new list item it should automatically sort after the last sorting criteria..
private ListViewColumnSorter lvwColumnSorter;
 

this.lstvReports.ListViewItemSorter = lvwColumnSorter;
 

//Lists for faster filtering

lstvicOnlyErrors = new ListViewGroup();

lstvicAllReports = new ListViewGroup();
 
 
 

lstvicAllReports.Items.Add(lviReportItems);
 

lstvReports.Items.Clear();

lstvReports.Items.AddRange(lstvicAllReports.Items);
 
 

lstvReports.Sort();

Open in new window

0
 
LVL 1

Author Comment

by:socom1985
ID: 24847115
I think I found the problem. When I click the standard column twice to sort it again then it works...
Just have to find out how to do it without that..
0
 
LVL 1

Author Comment

by:socom1985
ID: 24847127
Somehow the lstvListview.Sort(); method doesn't know the standard sorting.. so when I start the app and I remove and add the ListviewItem it doesn't work. But when I first click a column to sort it, then it works.. Anybody know where to set this?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24847151
adding a item adds at the end, it does not "sort" automatically at the place according to the sorting.
so, after adding a new item, you have to sort explicitly once according to the sort you want.
0
 
LVL 1

Author Comment

by:socom1985
ID: 24847160
I just did

            //Standart sort = Column 1
            lvwColumnSorter.SortColumn = 1;
            lvwColumnSorter.Order = SortOrder.Descending;


in the constructor
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24847171
that does not sort implicitly.
as I said, after each new insert (or bulk of inserts), you need to call the sort() method explicitly.
0
 
LVL 1

Author Comment

by:socom1985
ID: 24847233
no It works now because I insert the whole ListViewItemGroup new...
Thanks..
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now