 |
|
|
Hi,
I don't know if this is new to .NET-Framework 2.0, but the function SortBy calls
this.list.Sorting = SortOrder.None; which sets on my machine (with .NET 2.0, VS 2005) the list.ListViewItemSorter-property to zero. I deleted this line and everything works just fine now. Maybe you could update your article.
-- modified at 9:00 Tuesday 25th April, 2006
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
i had the same problem and then changed the function like: ----
public void SortBy(int index, bool asc) { if (this[index] == null) return;
this.index = index; // this.list.Sorting = SortOrder.None; this.list.Sorting = asc ? SortOrder.Ascending : SortOrder.Descending; } ----- now it works .I am working with .net framework 2.0, Visual Studio 2005
-- modified at 17:27 Thursday 13th July, 2006
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I just got this code saw the same issue and applied this same "fix", but then it took 2 clicks of the header to get it to sort by that column. One to select the column a second to get it to sort.
I modified the code to read like below to get it to sort onthe first click.
public void SortBy( int index, bool asc ) { if( this[index] == null ) return;
this.m_Index = index; this.m_List.Sorting = SortOrder.None; // Comparer is cleared by this line this.m_List.ListViewItemSorter = this; // Reset the comparer this.m_List.Sorting = asc ? SortOrder.Ascending : SortOrder.Descending; }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
If I had rearranged the columns (with .AllowColumnReorder = true) and then applied the sorting routine in the article, the control appears with the original column order, completely disregarging the way I had rearranged them.
How can I work around this?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
How do we sort checkboxes using this sorter ? I wrote a function but it doesn't seem to work .. any ideas ?
Regards, Shardool
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I would like to use this code, I have 4 listview columns which I would like to sort.
Could someone please post an example how to "use" this code in C#? There does not seem to be any usage example, or maybe it is so simple I don't get it.
Thanks.

Russell Mangel Las Vegas, NV
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
I agree this example is quite incomplete , and the link to Perez's original ListView sorting example is dead. Could someone elaborate on this. Do I include the ListViewSorter.cs file. The example code doesn't seem to referrence it. Thanks.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Here's how I got it to work:
1. Create a new ListViewSort object, associated with the list view I want to sort
ListViewSorter sorter = new ListViewSorter(listView1)
2. Set the Comparers property based on the column data type. Some comparers are included in the ListViewSorter class, but you have to code your own for custom data types
sorter.Comparers[0] = new ListViewSorter.Comparer(ListViewSorter.CompareNumbers); sorter.Comparers[1] = new ListViewSorter.Comparer(ListViewSorter.CompareStrings);
That's it!
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
I was very impreseed with gz's ListViewSorter code which sorts any column. It is well-written, self-describing, flexible and makes full use of C# language semantics. Much better, in my opinion, than the other samples that I have seen.
My question is that I would like to be notified when the sorting has finished? I need to apply a Mutex to the ListView so that other threads do not update its information while sorting is taking place. Otherwise the data integrity is disturbed.
I was thinking along the lines of creating a delegate which applies and then releases the Mutex when sorting has finished? It doesn't appear that ListView has an inbuilt way of protecting its data while it is being sorted.
Any ideas?
Tim
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, I would like to use this listview sorting code, can you please post a usage example. I don't understand how to use it.

Russell Mangel Las Vegas, NV
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Hi Russell,
The way to use this ListViewSorter class is to pass in a reference to your ListView along with a reference to an array of Comparers. Each Comparer will define the type of sorting for each column of your ListView.
Suppose we want to sort the first three columns of our ListView list...
ListViewSorter.Comparer[] comparers = new ListViewSorter.Comparer[] { new ListViewSorter.Comparer( ListViewSorter.CompareNumbers ), new ListViewSorter.Comparer( ListViewSorter.CompareStrings ), new ListViewSorter.Comparer( ListViewSorter.CompareDates ) };
ListViewSorter listViewSorter = new ListViewSorter( list, comparers )
This is all that is required for the ListViewSorter to take care of column click events and sort the ListView columns very quickly. I like this approach.
Regards,
Tim 
|
| Sign In·View Thread·PermaLink | 4.50/5 (2 votes) |
|
|
|
 |
|
|
I got this working, thanks.
However, the speed of populating the listview control is now very slow.
I am adding C:\Windows\system32\ filenames to listview:
Performance without ListViewSorter: 1916 Filenames added to listview in 704 Milliseconds.

Performance with ListViewSorter: 1916 Filenames added to listview in 15,390 Milliseconds

I am populating a listview control with filenames: I am using listView1.BeginUpdate() & listView1.EndUpdate().
Any Suggestions, this is unusable for me. Russell Mangel Las Vegas, NV
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Russel,
You are absolutely right that populating a listview control can take longer with a ListViewSorter. From what I can see, this is not because it adds a real overhead, but because the ListViewSorter forces the ListView to redraw itself every time that an entry is added. Without the ListViewSorter, the ListView only seems to redraw itself while adding "visible" entries and not for entries outside the visible window. In other words when the scroll bar appears and items are appended to the end of the list, populating is lightening fast because no redraw occurs.
I haven't got to the root of the problem yet, but to get around it I do a listView.Hide() when populating a large list and then a listView.Show() after I have finished. I am showing a ProgressBar superimposed on the grayed out list and this updates very rapidly with each item. This is ok. for my application because once I have populated the list with around 1000 items, I am only interested in changing the existing items. Remember that the parent form needs to be visible in order for the ListView to update correctly when it is not visible. So it's parent.Show() and list.Hide().
If you are continually adding a large amount of items then you probably want to keep the ListView visible. I am not sure what to do about this at the moment, apart from saying that appending at the end of list (out of sight) will be a lot quicker than inserting at the beginning.
I hope this helps. Keep me posted if you find a way out!
Tim
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Christian,
You need to create your own project and add your own ListView. "Add Existing Item" to your project for the unzipped source file "ListViewSorter.cs". Change the namespace "gz.Windows.Forms" to match that of your existing project. As mentioned in an earlier post, you then declare an instance of ListViewSorter.Comparer[] in your existing class and finally declare an instance of ListViewSorter itself, passing your ListView and the Comparer[] as paramters.
listViewSorter = new ListViewSorter( list, comparers );
I am not the original author so I can only apologise by proxy that the example is not a download and run one! It is fairly easy to get working though once these steps are taken.
Good luck!
Tim
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Okay so I've got a listview with 7 columns, and I've added this code to the form load event of my form class...
ListViewSorter.Comparer[] comparers = new ListViewSorter.Comparer[] { new ListViewSorter.Comparer( ListViewSorter.CompareNumbers), new ListViewSorter.Comparer( ListViewSorter.CompareStrings), new ListViewSorter.Comparer( ListViewSorter.CompareStrings), new ListViewSorter.Comparer( ListViewSorter.CompareStrings), new ListViewSorter.Comparer( ListViewSorter.CompareStrings), new ListViewSorter.Comparer( ListViewSorter.CompareStrings), new ListViewSorter.Comparer( ListViewSorter.CompareStrings) };
ListViewSorter listViewSorter = new ListViewSorter( listView, comparers );
It's compiling and active when I click a column, but no matter what column I click only the first column sorts... Any suggestions? Thanks!
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |