|
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-----
|
|
|
|
|
I have a weird problem. I have a listview that uses icons. So I have the listview small and large icons lists set. Now it appears that the ShowHeaderIcon's are no longer the arrows, but the icons from my image lists.
Is there an easy work around for this?
Thanks
KW
|
|
|
|
|
I haven't seen this happen. However, if you set the imagelist of the list's header control to your imagelist this is the behavior that you'll observe.
Do you have a small sample app that replicates this behavior?
If Java had true garbage collection, most programs would delete themselves upon execution - Robert Sewell
|
|
|
|
|
That is exactly what I am doing. I am using my own image lists. I several listviews within the software that pull from the same 16x16 and 32x32 image lists. As a temporary work around I just found some up and down arrow icons and added them as the first two images in my image lists.
I wasnt sure is there was a way to modify your code so the arrows you are creating internally are not using listview's image list property for storage.
Thanks,
KW
|
|
|
|
|
Anonymous wrote:
That is exactly what I am doing. I am using my own image lists
This I know, what I said was "if you set the imagelist of the list's header control to your imagelist". What I don't know is if the list control resets the image list of the header control whenever it's image list is changed. (Which seems to be the problem by the way)
If Java had true garbage collection, most programs would delete themselves upon execution - Robert Sewell
|
|
|
|
|
No I only specify the small and large lists. Sorry I miss-understood you.
|
|
|
|
|
I have a similar problem, I add icons to the listview (dynamicly using this code http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/SysImageList/article.asp ), however using this technique my sort icons get replaced by those in the ImageList of the ListView. At this point I don't know if it's an error on the library,your control or my code.
|
|
|
|
|
The work around I came up with for this problem was to find my own "up" and "down" arrow icons (or gif's with transparent background) and add them as the first two images in you image list(s).
Hope this helps,
kWa
|
|
|
|
|
As stated above, I'm using the http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/SysImageList/article.asp library to create dinamicaly icons for the list. This library fools the control in thinking it has a Imagelist but i don't know if it really exist since (if I understand it correctly, I'm not into unmanaged code) it seems to work with handles which are not icons...
How does this blend with your methods that create the up-down arrows?
Could the up-down arrow methods be extracted from your code? If so how?
Does someone think it's possible to adapt the library from above so it would know to create those arrows in the right posision? The strangest thing is that for me the effect is to show the shared-folder-on-network and shortcut icon's which are not supposed to be generated by the library (or maybe it gives those icons for 0 and 1 as indexers (can one say that for unmanaged c++)?
|
|
|
|
|
I found if I add the following method to the ListViewSortManager class and call it any time I update the imagelists, it works fine:
public void SetHeaderImageList()
{
SetHeaderImageList(this.m_list, this.m_imgList);
}
It's a real shame that the standard ListView doesn't have events for changing imagelists otherwise you could register for it like the column click and handle it automatically.
|
|
|
|
|
You must place creating ListViewSortManager on form_load event, not in form constructor. That helps me.
|
|
|
|
|
Just what the doctor ordered.
|
|
|
|
|
pbible wrote:
Just what the doctor ordered
Thank you!
The nice thing about C++ is that only your friends can handle your private parts.
|
|
|
|
|
Hi,
I have a ListView with alternate row colors! After sorting a column, the rows colors appear mixed
Is there a way to exented this nice class to handle this problem?
Eddie, thanks for yor nice class!
Max Glaser
Email: MaxGlaser@gmx.net
|
|
|
|
|
GlaserSoft wrote:
I have a ListView with alternate row colors! After sorting a column, the rows colors appear mixed... Is there a way to exented this nice class to handle this problem?
I had the same issue and extended the class to add an event to be raised after each sort is complete. Then I could just add a listener to the event to call a method which sets the background colors on this ListView each time a sort occurs.
The only change necessary to Eddie's code is to mark as virtual the method public void Sort(Int32 column, SortOrder order)
Here's my code:
using System;
using System.Windows.Forms;
namespace MyApplication
{
public class EventRaisingSortManager : EV.Windows.Forms.ListViewSortManager
{
public EventRaisingSortManager(ListView list, Type[] comparers) :
base(list, comparers)
{
}
public override void Sort(Int32 column, SortOrder order)
{
base.Sort(column,order);
OnSorted(column,order);
}
private void OnSorted(Int32 column, SortOrder order)
{
if (Sorted != null)
Sorted(this,new SortedEventArgs(column,order));
}
public event SortedEvent Sorted;
}
public delegate void SortedEvent(object sender, SortedEventArgs e);
public class SortedEventArgs : System.EventArgs
{
int _column;
SortOrder _order;
public SortedEventArgs(Int32 column, SortOrder order) : base()
{
this._column = column;
this._order = order;
}
public Int32 Column
{
get { return _column; }
set { _column = value; }
}
public SortOrder Order
{
get { return _order; }
set { _order = value; }
}
}
}
|
|
|
|
|
Hi Eddie
I like your code, but I would like to send you a change I made:
I created a date column, and the sorting crashed the program because my dates were not in a proper date-time format.
So I modified the OnCompare of each class like so:
private bool m_SortError=false;
protected override Int32 OnCompare(String lhs, String rhs)
{ //Error-handling added by Willem Semmelink
if (m_SortError) return 0; // dont show error message for each row
else {
try { // insert here Eddie's original code - int/date/string compare as the case may be
return DateTime.Parse(lhs).CompareTo(DateTime.Parse(rhs));
} catch(Exception E) {
m_SortError=true;
MessageBox.Show(E.Message);
}
return 0;
}
}
Perhaps, in stead of repeating this code in each OnCompare method, I should have followed a true O-O design and modified the base class, but this works for me.
Now, instead of crashing the application, I show the error to the user, and let him/her continue.
Just thought you may find it useful, too.
Greetings,
Willem Semmelink
|
|
|
|
|
WillemSe wrote:
and the sorting crashed the program because my dates were not in a proper date-time format. So I modified the OnCompare of each class like so:
I thought about adding something similar but dropped the idea because I think that ill-formed data shouldn't be allowed to be inserted in the list in the first place. Besides, all the checks would impose a large overhead to the sort process.
WillemSe wrote:
Perhaps, in stead of repeating this code in each OnCompare method, I should have followed a true O-O design and modified the base class, but this works for me.
I think you meant: create a derived class and add the extended functionality there.
There are only 10 kind of people in the world: those who understand binary and those who don't.
|
|
|
|
|
re:
//I think you meant: create a derived class and add the extended functionality there.
no, what I meant is that I would have liked to modify only ListViewTextSort whilst in the current implementation, I added the try..catch in each class:
* ListViewTextSort;
* ListViewTextCaseInsensitiveSort;
* ListViewDateSort;
* ListViewInt32Sort;
* ListViewInt64Sort;
* ...
I meant that I would have liked to implement error-checking only in ListViewTextSort so the others could inherit it - but it was easier to duplicate the code in each subclass.
The reason why the date failed on me was probably due to culture information - feeding a date in a non-American date format. So I will maybe spend some more time on it later to add culture info: I would like to do the comparison somewhat like this:
return DateTime.Parse(lhs,m_dateFormat,System.Globalization.DateTimeStyles.NoCurrentDateDefault).CompareTo(
DateTime.Parse(rhs,m_dateFormat,System.Globalization.DateTimeStyles.NoCurrentDateDefault));
where dateFormat is a System.Globalization.CultureInfo.
This will give me the control to determine whether the dates are in "dd-mm-yyyy", "mm-dd-yyyy", or "yyyy-mm-dd".
re:
//I think that ill-formed data shouldn't be allowed to be inserted in the list in the first place.
I agree, but in my experience, what should happen and what actually happens in a development environment are not the same.
Greetings
Willem Semmelink
|
|
|
|