forked from oozcitak/imagelistview
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added IComparer override to custom columns.
- Loading branch information
Showing
4 changed files
with
30 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
// Ozgur Ozcitak ([email protected]) | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Resources; | ||
using System.Windows.Forms; | ||
|
@@ -177,6 +178,11 @@ public int Width | |
mImageListView.Refresh(); | ||
} | ||
} | ||
/// <summary> | ||
/// Gets or sets the comparer used while sorting items with this custom column. | ||
/// </summary> | ||
[Browsable(false)] | ||
public IComparer<ImageListViewItem> Comparer { get; set; } | ||
#endregion | ||
|
||
#region Custom Property Serializers | ||
|
@@ -213,6 +219,7 @@ public ImageListViewColumnHeader(ColumnType type, string key, string text, int w | |
mImageListView = null; | ||
owner = null; | ||
mGuid = Guid.NewGuid(); | ||
Comparer = null; | ||
|
||
mType = type; | ||
mKey = key; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,12 @@ | |
// Ozgur Ozcitak ([email protected]) | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Collections; | ||
using System.Windows.Forms; | ||
using System.Drawing; | ||
using System.Text.RegularExpressions; | ||
using System.Windows.Forms; | ||
|
||
namespace Manina.Windows.Forms | ||
{ | ||
|
@@ -641,8 +641,7 @@ internal int IndexOf(ImageListViewItem item) | |
/// </summary> | ||
internal int IndexOf(Guid guid) | ||
{ | ||
ImageListViewItem item = null; | ||
if (lookUp.TryGetValue(guid, out item)) | ||
if (lookUp.TryGetValue(guid, out ImageListViewItem item)) | ||
return item.Index; | ||
return -1; | ||
} | ||
|
@@ -772,10 +771,10 @@ private void AddRemoveGroupItem(int index, bool add) | |
/// </summary> | ||
private class ImageListViewItemComparer : IComparer<ImageListViewItem> | ||
{ | ||
private ImageListViewColumnHeader mGroupColumn; | ||
private readonly ImageListViewColumnHeader mGroupColumn; | ||
private ImageListViewColumnHeader mSortColumn; | ||
private SortOrder mGroupOrder; | ||
private SortOrder mSortOrder; | ||
private readonly SortOrder mGroupOrder; | ||
private readonly SortOrder mSortOrder; | ||
|
||
public ImageListViewItemComparer(ImageListViewColumnHeader groupColumn, SortOrder groupOrder, ImageListViewColumnHeader sortColumn, SortOrder sortOrder) | ||
{ | ||
|
@@ -809,12 +808,9 @@ private int CompareStrings(string x, string y, bool natural) | |
|
||
string xpart = xparts[i]; | ||
string ypart = yparts[i]; | ||
|
||
int xi = 0; | ||
int yi = 0; | ||
int res = 0; | ||
|
||
if (int.TryParse(xpart, out xi) && int.TryParse(ypart, out yi)) | ||
if (int.TryParse(xpart, out int xi) && int.TryParse(ypart, out int yi)) | ||
res = (xi < yi ? -1 : (xi > yi ? 1 : 0)); | ||
else | ||
res = string.Compare(xpart, ypart, StringComparison.InvariantCultureIgnoreCase); | ||
|
@@ -925,7 +921,10 @@ public int Compare(ImageListViewItem x, ImageListViewItem y) | |
result = (x.FocalLength < y.FocalLength ? -1 : (x.FocalLength > y.FocalLength ? 1 : 0)); | ||
break; | ||
case ColumnType.Custom: | ||
result = CompareStrings(x.SubItems[mSortColumn].Text, y.SubItems[mSortColumn].Text, natural); | ||
if (mSortColumn.Comparer != null) | ||
result = mSortColumn.Comparer.Compare(x, y); | ||
else | ||
result = CompareStrings(x.SubItems[mSortColumn].Text, y.SubItems[mSortColumn].Text, natural); | ||
break; | ||
default: | ||
result = 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters