Comments (5)
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.
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".
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.
Am I doing something wrong?
Maybe this is normal operation?
Thanks for your help,
from imagelistview.
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.
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.
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.
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.
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)
- Image For FileIcon HOT 1
- Auto Clear Items HOT 6
- Sort Order Can't Be Changed HOT 2
- After set thumbnail size,thumbnail can't show
- Thumbnail Generation Delay when Adding Large Resolution Images
- Thumbnail displaying delay and slowing windows system
- Multiple ImageListViews on Same Form HOT 2
- Small Additional Drag & Drop Items Bug HOT 1
- How to visualize the top bar? HOT 2
- Idea, Can add SelectedItemsClear as default behavior ?
- Drag and drop related problem HOT 1
- Target .NET Standard 2.0 to Support .NET Core Build HOT 6
- Is it possible to show pdf files as well? HOT 2
- Need to know scroll position while scrolling for Infinite scrolling HOT 6
- NU1701 | .Net 5 not compatible
- ImageListView doesn't display the ampersand character
- .NET 6 support HOT 1
- Image files locked and cannot perform file modifications
- Filename display should be optional via a boolean property
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imagelistview.