|
Could you please explain it more? I also have the same problem.
|
|
|
|
|
Hi Epon
because ListViewSortManager is a external control I thought I have to switch off the ListViewSortManager control for non sorting. But you have to delete the ListViewItemSorter in the ListView control (listView.ListViewItemSorter = null).
Excample:
SortOrder ordertemp = m_sortMgr.SortOrder;<br />
int sortColumn = m_sortMgr.Column;<br />
listView1.ListViewItemSorter = null;<br />
listView1.BeginUpdate();<br />
listView1.Items.Clear();<br />
<br />
... fill listview ... <br />
<br />
if((sortColumn > -1) && (sortColumn < listView1.Columns.Count))<br />
m_sortMgr.Sort(sortColumn,ordertemp); <br />
listView1.EndUpdate();
Ciao, Jimmy S.
|
|
|
|
|
Try using the SortEnabled property of the ListViewSortManager object:
sortManager.SortEnabled = false; Yes, I know, a few days too late!
[EDIT: I just read that property is new as of realease 1.4]
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I don't know if it's too late for this, but I didn't see where anyone had posted an actual VB.NET version, except for that one that doesn't include the arrow, and seeing as how I'm trying to keep the software on my pc at work 'legal', meaning I do not have C Sharp installed, I decided to convert it. It is a straight conversion, I didn't change anything or add anything.
Here is the url: http://bellsouthpwp.net/j/a/jasonage/ListViewSortManager.zip
|
|
|
|
|
Have you considered using the HDF_SORTUP and HDF_SORTDOWN flags for the arrow on your header? This gives you Explorer-style up/down arrows without having to worry about image-lists, etc.
It is available with ComCtl 6 or later - which is pretty much everyone (although I admit that in my implementation I check the version and regress to images if prior to 6 - using your approach for drawing the bitmaps).
Arlen (www.cowthulu.com)
|
|
|
|
|
Thanks a bunch! This is exactly what I've been looking for -- even implements the sort state icons!
Also, wrote myself a custom sort type -- ListViewIPSort. Great code, thanks!
Skydive -- Testing gravity, one jump at a time.
|
|
|
|
|
Can this have a VB version especially the graphics part (drawing the header order icon)?
I have converted that part to VB but Im having problems: the icon is not showing up.
|
|
|
|
|
Well, I'm not a VB developer, so I can't really help you there. But, that said, you CAN use this component in VB.NET projects, just create an C# class library and reference it from you project.
If Java had true garbage collection, most programs would delete themselves upon execution - Robert Sewell
|
|
|
|
|
You have?
Could/would you provide a link or something?
I'm having trouble with the types-array.
Thank's in advance!
Stevie
Greetings,
Stephan Eberle
hawke@deltacity.org
|
|
|
|
|
I have created my own listview sorter.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2435&lngWId=10
|
|
|
|
|
I'm new to C#. I have a program that populates a listview in the Load method. How to I simulate a mouse click on a column header to get the view sorted (so the sort order image is displayed in the column header).
Thanks in advance,
Hal
|
|
|
|
|
You don't have to "simulate" a mouse click on the column header, you just have to call Sort() with the column number and the sort order.
If Java had true garbage collection, most programs would delete themselves upon execution - Robert Sewell
|
|
|
|
|
Thank you for the reply. When I try Sort(0, SortOrder.Ascending); the compiler tells me that the name Sort does not exist in the class or namespace. Trying ListViewSortManager.Sort(0, SortOrder.Ascending); results in the following error:
An object reference is required for the nonstatic field, method, or property 'EV.Windows.Forms.ListViewSortManager.Sort(int, System.Windows.Forms.SortOrder)'
Regards,
Hal
|
|
|
|
|
Are you calling Sort() on an instance of ListViewSortManager()?
i.e.
<code>
m_sortMgr = new ListViewSortManager(m_list, new Type[] {
typeof(ListViewTextSort),
typeof(ListViewTextCaseInsensitiveSort),
typeof(ListViewInt32Sort),
typeof(ListViewDoubleSort),
typeof(ListViewDateSort)
});
m_sortMgr.Sort(0, SortOrder.Ascending);
</code>
<hr><small><i>If Java had true garbage collection, most programs would delete themselves upon execution - Robert Sewell</i></small>
|
|
|
|
|
Thank you. I did not have m_sortMgr. on the Sort statement. It is working fine now.
Regards,
Hal
|
|
|
|
|
Just glad to help.
If Java had true garbage collection, most programs would delete themselves upon execution - Robert Sewell
|
|
|
|
|
Hi,
quite a newbie in C#....
In my procjet i have to use 3 listviews with different number of columns.
May i use only one ListviewSortMAnager.cs or i have to add one for each listview?
Thanks.
|
|
|
|
|
A ListViewManager only handles one list at the time; so you need 3 ListViewManagers, one for each listview.
If Java had true garbage collection, most programs would delete themselves upon execution - Robert Sewell
|
|
|
|
|
Hi,
I've got a problem with sorting on an integer column. It seems to sort it like text. I want to show some numbers from High to Low, but I get this:
999
998
997
996
1003
1002
1001
1000
Any ideas what I'm doing wrong?
Thanks
/goat
|
|
|
|
|
Are you using a ListViewIntegerSort for that particular column?
If Java had true garbage collection, most programs would delete themselves upon execution - Robert Sewell
|
|
|
|
|
I was using a ListViewInt32Sort.
There doesn't appear to be a type ListViewIntegerSort.
Perhaps I'm not using it correctly? I'm using it in VB by the way, with
this code to initialize:
oListViewSorter = New ListViewSortManager(lvQuotes, _
New Type() {GetType(EV.Windows.Forms.ListViewInt32Sort), _
GetType(EV.Windows.Forms.ListViewTextCaseInsensitiveSort), _
GetType(EV.Windows.Forms.ListViewTextCaseInsensitiveSort), _
GetType(EV.Windows.Forms.ListViewDateSort), _
GetType(EV.Windows.Forms.ListViewTextCaseInsensitiveSort)})
/goat
|
|
|
|
|
just bumping this issue.
thanks,
/goat
|
|
|
|
|
Thanks for the code.
I have converted the ListViewSortManager control C# code to VB.NET and I was testing functionality to make sure it matched your sample. One thing I needed to add immediately was to 'listview.items.clear', reload the listview with different search results and restore the sorting. When a large number of results returned the sorting needed to be turned off or the item loading would take to long. So I did:
-----------------------------
m_sortMgr = Nothing
ListView.ListViewItemSorter = Nothing
LoadListViewItems()
m_sortMgr = New ListViewSortManager(Me.lvItems, New Type() { _
GetType(ListViewTextSort), _
GetType(ListViewTextSort), _
GetType(ListViewTextSort), _
GetType(ListViewTextSort), _
GetType(ListViewTextSort), _
GetType(ListViewTextSort) _
})
m_sortMgr.Sort(sort_column, sort_order)
------------------------------
And it works great in all columns - except the LAST column. I did some more testing and I noticed the same problem in your code. When clicking on the column header of the last column, then the previous column, then back to the last column I noticed the sort direction and sort image flip as well as sorted column change. On all the other columns the sort direction would not change when column changed. It came to my attention on one of my lists where the last two columns where dates and integers. An error would occur trying to evaluate the order of the integers column in the DateTime.Parse sorter!
Have you noticed this problem? Could you possibly suggest a fix or provide some clues?
Gerry
________________________________
Gerry Kichok
Software Developer
Crazy Rides - Mississauga, Ontario, Canada
E-mail: gkichok@crazyrides.com
Website: http://www.crazyrides.com
|
|
|
|
|
Eddie, great code! I'm using some ideas you used in your code but I'm having a strange problem. I do set the header control's ImageList and the "arrows" show up but they are actually the first two images in the ImageList for the ListView .
I've combed the PSDK with which I've used for years and neither docs nor experience explain this. Even if the poorly wrapped SysListView32 common control did set it's ImageList for both the view and headers, setting the header's ImageList after the control is created should re-set the ImageList to what I specify...but it isn't.
Any ideas why this might be happening?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Go figure - I spend a couple hours last night on this and right after I posted the previous message, a thought hit me. I checked the messages for setting the ImageList for a ListView and the header control and they're the same. I know that a lot of controls pass their messages down to their children, so the the same ImageList was being set on the header control as well. If I set the ImageList for the ListView first, then the header control, all is well.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|