Solved

c# ListView sorting problem

Posted on 2009-07-14
8
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 143

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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
 
LVL 143

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 143

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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 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