Code Monkey home page Code Monkey logo

Comments (5)

oozcitak avatar oozcitak commented on July 24, 2024

I just tested with a few images and sorting seems to be fine. It seems to be fine in your screenshot as well. Can you please show where you think sorting fails?

from imagelistview.

eXclusif20 avatar eXclusif20 commented on July 24, 2024

Hi,

Thank you for your prompt response.

This is my case. I want to group the items on the file type (column 4).

So I added the commands to my code:

Me.imgLvwDocuments.GroupColumn = 4
Me.imgLvwDocuments.GroupOrder = SortOrder.AscendingNatural

Instead of having 3 groups in total. A first group named "JPG file", a second group named "TIFF file" and a third group named "Luminar 2018 ProdID".

group column

I get a first group named "F" (see 1) which contains the JPG and TIFF files and a second group called "L" (see 2) which contains the Luminar 2018 ProgID files.

Same problem when I try to group on column 5. I find myself with only one group named "C" which is the first character of the paths.

group column path

Am I doing something wrong?
Maybe this is normal operation?

Thanks for your help,

from imagelistview.

oozcitak avatar oozcitak commented on July 24, 2024

By default, groups from string columns only take into account the first letter of each item. The way custom grouping works is that you supply a group name to the control along with a hash code with that group, so all items with the same hash code will be grouped under that group name. In the code you posted above, a hash code is calculated from the first three letters of the item text. If for example you want the control to group by the entire file path you can create a custom group like this:

private class CustomGrouper : ImageListView.IGrouper
{
    public ImageListView.GroupInfo GetGroupInfo(ImageListViewItem item)
    {
        // group name is the file path
        // to group by file type instead replace FilePath below with FileType
        string str = item.FilePath;
        // hash code is calculated from entire file path string
        return new ImageListView.GroupInfo(str, str.GetHashCode());
    }
}

The above group calculates the hash code from the entire file path of each item. You can assign to the control for example in your form's constructor:

public DemoForm()
{
    InitializeComponent();

    imageListView1.Columns.Add(ColumnType.Name);
    imageListView1.Columns.Add(ColumnType.Dimensions);
    imageListView1.Columns.Add(ColumnType.FileSize);
    imageListView1.Columns.Add(ColumnType.FilePath);
    imageListView1.Columns.Add(ColumnType.DateModified);

    // set the custom grouper
    imageListView1.Columns[3].Grouper = new CustomGrouper();
    imageListView1.GroupColumn = 3;
    imageListView1.GroupOrder = SortOrder.AscendingNatural;

    imageListView1.View = View.Details;
}

In the CustomGrouper you need to supply both a group name and a hash code, because sometimes you want a different group name than the column text, for example when grouping by modified date, you may want to display group names as Last Week, Last Month, Older, etc. instead of the date string.

from imagelistview.

eXclusif20 avatar eXclusif20 commented on July 24, 2024

Once again thank you for your help.
I managed to convert the C # code to VB, and it was not easy for me.

Grouping by filepath works great.

capture20200327100817175

capture20200327100825842

On the other hand concerning the grouping by type of file, I meet an unhandled error if I make the grouping before the list is completely loaded. If I wait for the complete loading of the list, the exception is not thrown and the grouping works.
I don't understand why because the code is strictly the same as for the filepath.

capture20200327100847652

capture20200327100901940

capture20200327101053556

Also, how do I get the ascending sort on the name of the groups? It may be simple, but I can't do it and I can't figure out why.

Do you have any idea what I'm doing wrong?

thank you so much

from imagelistview.

oozcitak avatar oozcitak commented on July 24, 2024

I found a bug in file type retrieval code and fixed it. I also added a new event which will be fired after file types are retrieved by the control. So please upgrade ImageListView to version 13.8.2 before proceeding.

On the other hand concerning the grouping by type of file, I meet an unhandled error if I make the grouping before the list is completely loaded.

This happens because file type is loaded by a background thread. You need to account for FileType being null because the background thread has not yet processed the item:

Private Class FileTypeGrouper
    Implements ImageListView.IGrouper

    Public Function GetGroupInfo(item As ImageListViewItem) As ImageListView.GroupInfo Implements ImageListView.IGrouper.GetGroupInfo
        Dim str = item.GetSubItemText(ColumnType.FileType)
        If str Is Nothing Then
            ' item is not yet processed by the background thread
            ' group it under the "Unknown" group, we will fix that later
            ' also return a large hash code so that the "Unknown" group is 
            ' displayed at the bottom of other groups
            Return New ImageListView.GroupInfo("Unknown", Integer.MaxValue)
        Else
            Return New ImageListView.GroupInfo(str, str.GetHashCode())
        End If
    End Function
End Class

You also need to listen to the ShellInfoCached which was added with version 13.8.2 and use it to re-group the items:

Private Sub imageListView1_ShellInfoCached(sender As Object, e As ShellInfoCachedEventArgs)
    ' this event is fired when a file type's shell info is cached
    ' we re-sort items, so that groups are updated by our FileTypeGrouper
    ' after that some of the items in the "Unknown" group above will be assigned the proper group
    imageListView1.Sort()
End Sub

I prepared a demo project for you: ILV_GroupingDemo.zip

from imagelistview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.