Notifications
Clear all

[Closed] dotNet "sort" for listviews

Hi, I wa wondering how one would go about implementing the dotNet “sort” system for sorting columns in listviews? Currently Im doing it with sort() and a few of my own variable to store the last sort type. What adavantages does the dotNet method give (if any?)

5 Replies

You may have already determined that to sort by column you need to assign a sorter to your listview’s ListViewItemSorter property.

A ‘vanilla’ sorter, MXS_dotNet.ListViewItemComparer, is included in the MXS_dotNet tools that ship with max. Note that this one will only sort in ascending order.

You can see how it is used in test code located at the end of the following standard script file: <maxdir>\stdplugs\stdscripts\NET_ListViewWrapper.ms

The C# source for this sorter is located in the SDK:
<maxsdkdir>\samples\maxscript\mxsdotnet\ListViewItemComparer.cpp

If you need more control and want to mess around with a custom sorter, have a look at this snippet: http://forums.cgsociety.org/showpost.php?p=6001914&postcount=349

.biddle

 PEN

Very cool bit of code there Mike. I still have not tried anything like that. I how ever have just used my own QSort functions for this and then just repopulated the listView. I’m going to assume Mike that doing it in DotNet would be faster with large amounts of data? I also tend to store all my data in an array of structs and then populate the listView with it and want to be able to sort the array. Part of the reason for this is that often I want tools to be usable without a UI or the data needs to be persistent in the scene so I have to have it stored anyways.

Yes, I found that using a sorter is considerably faster than sorting and re-populating. It feels more like going with the .NET flow instead of fighting it. My motivation for working this stuff all out was to speed up legacy code I was asked to maintain that sorted by columns externally, pretty much as you described. Once you hide the C# source code & compiler away in a reusable support file, I think you will find your listview code become much, much simpler.

Have you considered wrapping your structs in a dotNetMXSValue and then storing them in the tags of a treenode? You’d get a hierarchy of structs, instead of an array of structs. It’s pretty the definitive example of what dotNetMXSValue is good for.

.biddle

 PEN

Yes I still all sorts of things in the tag values. Those come in real handy, not tried what you suggested, not sure that I have needed to but I will keep it in mind.

That sounds pretty useful. Could we get a quick code sample of that?